Question
Consider the following code. int x = 0; while (x < 5) { System.out.print(x + ); x++; } System.out.println(x); Suppose the initialization int x
Consider the following code.
int x = 0;
while (x < 5) {
System.out.print(x + " ");
x++;
}
System.out.println(x);
Suppose the initialization int x = 0; is replaced. What will be printed by each of the following replacements?
1. int x = 1;
2. int x = 2;
3. int x = 5;
4. int x = 6;
Ans Choices
A. 1 2 3 4 5
B. 6
C. 2 3 4 5
D. 5
Second Part
Consider the following code.
int x = 0;
while (x < 5) {
System.out.print(x + " ");
x++;
}
System.out.println(x);
Suppose the test x < 5 is replaced. What will be printed for each of the following replacements?
1. x < 0
2.x >= 0
3.x < 3
4.x <= 3
Ans Choices:
A. 0
B. 0 1 2 3
C.results in an infinite loop
D.0 1 2 3 4
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