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 (vi): for( ... ; x <= __________ ; x += 0.5)
Topic: Loop condition with a double
Try it
Pick an option and check your answer. The full worked answer is below either way.
Answer
(b) x <= 5.0.
Careful reading is needed here. The blank sits AFTER "x <=" in the printed program, so what is required is the limit itself — 5.0 — giving the complete condition x <= 5.0. The series must include 5.0, so the operator is <= and not <. Option (a) reverses the comparison, (c) would be true only at the single value 5.0, and (d) is an assignment rather than a test.
x <= 5.0.