176k views
0 votes
Consider this program segment: int newNum = 0, temp; int num = k; // k is some predefined integer value 0 while (num > 10) { temp = num % 10; num /= 10; newNum = newNum * 10 + temp; } System.out.println(newNum); Which is a true statement about the segment? I If 100 <= num <= 1000 initially, the final value of newNum must be in the range 10 <= newNum <= 100. II There is no initial value of num that will cause an infinite while loop. III If num <= 10 initially, newNum will have a final value of 0.

User Bodokh
by
5.1k points

1 Answer

4 votes

Answer:

All of these statements are true.

Step-by-step explanation:

Since the while loop is reversing the integer number and leaving the highest order digit in the num and stores the reversed number in the newNum variable.

It skips one digit so if the num is in the range of [100,1000] it will result in a number between 10 and 100.

This loop can never go in infinite loop for any initial value of num because the loop will run as many times as the number of digits.

and if the value of the num is <=10 the while loop will never run and the value of newNum will be 0.

User BarathVutukuri
by
5.9k points