Question: For the following program segment, give the output produced by the segment: 1 2 3 4 5 6 int i=0, j=1; while (i < 5)

  1. For the following program segment, give the output produced by the segment:

1

2

3

4

5

6

int i=0, j=1;

while (i < 5) {

j = j * 2;

i = i + 1;

}

System.out.println("Final value is: "+j);

Final value is: 2 (I think it is 2)

  1. For the following program segment, give the output produced by the segment:

1

2

3

4

5

6

7

8

int answer=1;

boolean stop=false;

while ( !stop ) {

answer = answer * (answer + 1);

if (answer >= 15) {

stop = true; }

}

System.out.println("The answer is: "+answer);

Please help me with the two questions, thank you so much

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!