Question: M 2 P 2 - Q 2 1 Code 4 : int sum = 0 ; int number = 1 ; while ( number s

M2P2-Q21
Code 4:
int sum =0;
int number =1;
while (number s=5){
sum = sum + number;
number ++;
}
System.out.println(sum);
Code 4 also contains a sequence-generating
loop. The variable number is initialized, tested, and
updated the same way as in Code 3. What values
does variable sum take on from line 3 to line 9?
What does the code print?
M 2 P 2 - Q 2 1 Code 4 : int sum = 0 ; int number

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 Programming Questions!