Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Which of the following is equivalent to the code segment below? if (x > 2) x = x * 2; if (x > 4) x
Which of the following is equivalent to the code segment below?
if (x > 2) x = x * 2; if (x > 4) x = 0;
if (x > 2) x *= 2; |
if (x > 2) x = 0; |
if (x > 2) x = 0; else x *= 2; |
x = 0; |
21
Which of the following is equivalent to the code segment below?
if (x > 0) x = -x; if (x < 0) x = 0;
if (x<0) x = 0; |
if (x < 0) x = 0; else x = -1; |
if (x > 0) x = -x; else x = 0; |
x = 0; |
if (x>0) x = 0; |
31
What would the following print?
int x = 3; int y = 2; if (x > 2) x++; if (y > 1) y++; if (x > 2) System.out.print("first "); if (y < 3) System.out.print("second "); System.out.print("third");
third |
first second |
first second third |
first |
first third |
41
What would the following print?
int x = 3; int y = 2; if (y / x > 0) System.out.print("first "); System.out.print("second ");
first |
first second |
second |
Nothing will be printed |
51
What would the following print?
int x = 3; int y = 2; if (y / x > 0); { System.out.print("first "); System.out.print("second "); }
second |
first second |
Nothing will be printed |
first |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started