Given below is a class with the following specifications: class name : Number void Display(int n) - To extract and print each digit of the given number, from the last digit to the first digit, on separate lines. Example: n = 674 Output: 4 / 7 / 6 void Display() - To print numbers from 0.5 to 5.0 with an update of 0.5. Fill in the blanks of the given program with appropriate statements: class (i) __________ { void Display(int n) { while( (ii) __________ ) { int rem = (iii) __________ System.out.println(rem); n = (iv) __________ } } void Display() { for( (v) __________ ; x <= (vi) __________ ; x += 0.5) System.out.println(x); } }
Fill in blank (ii): while( __________ )
Topic: Loop condition for digit extraction
Try it
Pick an option and check your answer. The full worked answer is below either way.
Answer
(b) n > 0.
Digit extraction continues while there are digits left, and repeated integer division reduces the number towards 0 — 674 becomes 67, then 6, then 0. So the loop must run while n > 0. Option (c) would never enter the loop for a positive number, (a) is wrong for positive input, and (d) is an ASSIGNMENT, not a comparison, so it would not even compile in a condition.
n > 0.