
What is the output of the following fragment? (3 points)
int i = 1; int j = 1; while (i < 5) { i++; j = j * 2; } System.out.println(j);

We have modified your code:
class Output {
public static void main(String[] args) {
int i = 1;
int j = 1;
while (i < 5) {
i++;
j = j * 2;
}
System.out.println(j);
}
}
In the code, value of i incremented 4 times, so at first, value of j=1, then 1*2=2
value of j is changed to 2 so j=2, then 2*2=4
value of j is changed to 4 so j=4, then 4*2=8
value of j is chnaged to 8 so j=8, then 8*2=16
So at last we get the value of j after last
counter is 16, so output is 16.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.