Question: All Java Statements 1. What does this print? Note: theres nothing to fix in this loop, its OK. // How do the print statements differ

All Java Statements

1. What does this print? Note: theres nothing to fix in this loop, its OK.

// How do the print statements differ in that one is inside the loop and the other is outside?

int num= 0;

int limit = 5;

while (num <= limit) // do this unless the value in num is greater than the value in limit

{

num++; // this adds one to num (its a postfix increment operator) ++num; also works

System.out.println("Value of num is: " + num);

} System.out.println("Last Value is: " + num); // your brief answer:

2. What happens here? How can the code be fixed to eliminate the problem(s)?

int count = 0;

while (count < 5)

{

count += num; // this is a shortcut assignment operator that means count = count + num;

num++; // this adds one to num

System.out.println(count2);

} // your brief answer:

3. What needs to be fixed so that the while loop will print the product of the odd integers between 0 and 5, inclusive (1*3*5 = 15)?

int i = 0;

int product = 1;

while (i <= 5)

{

if (i % 2 != 0) // test if i is odd

product *= i5; // same as product = product * i5;

i--; // same as i = i - 1;

}

System.out.println("Product is: " + product); // your brief answer:

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!