Consider the following code. int x = 0; while (x < 5) { System.out.print(x + \"
ID: 3835859 • Letter: C
Question
Consider the following code.
int x = 0;
while (x < 5) {
System.out.print(x + " ");
x++;
}
System.out.println(x);
Suppose the statement x++; is replaced. What will be printed for each of the following replacements?
1.x--;
2.x += 2;
3.x += 3;
4.x += x + 1;
Answer Choices
A. 0 3 6
B. results in an infinite loop
C. 0 1 3 7
D. 0 2 4 6
Second Part
How do you declare a Random variable and assign a new Random object to the variable?
A. new Random(r);
B. r = new Random( );
C. Random r;
D. Random r = new Random( );
E. Random r = Random.new( );
Explanation / Answer
Answers:
1.x--; will lead to B. results in an infinite loop
2.x += 2; will print D. 0 2 4 6
3.x += 3; will print A. 0 3 6
4.x += x + 1; will print C. 0 1 3 7
How do you declare a Random variable and assign a new Random object to the variable?
Answer: D. Random r = new Random( );
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.