Computer Applications
Answer
for (int i = 53; i >= 45; i -= 2)
Reason
- Loop (
i > 45; i -= 2
): The loop starts at 53 and decreases by 2 each time. The values are 53, 51, 49, and 47, which totals 4 iterations before the conditioni > 45
becomes false. - Loop (
i < 57; i++
): The loop starts at 53 and increments by 1 each time. The values are 53, 54, 55, and 56, which totals 4 iterations before the conditioni < 57
becomes false. - Loop (
i >= 45; i -= 2
): The loop starts at 53 and decreases by 2 each time. The values are 53, 51, 49, 47, and 45, which totals 5 iterations before the conditioni >= 45
becomes false. - Loop (
i >= 45; i--
): The loop starts at 53 and decreases by 1 each time. The values range from 53 to 45 inclusive, which totals 9 iterations.
Related Questions
Which of the following are entry controlled loops?
(a) for
(b) while
(c) do..while
(d) switch
- only a
- a and b
- a and c
- c and d
Give the output of following code and mention how many times the loop will execute?
int i; for( i=5; i>=1; i--) { if(i%2 == 1) continue; System.out.print(i+" "); }
Rewrite the following do while program segment using for:
x = 10; y = 20; do { x++; y++; } while (x<=20); System.out.println(x * y );
Define a class to accept a number from user and check if it is an EvenPal number or not.
(The number is said to be EvenPal number when number is palindrome number (a number is palindrome if it is equal to its reverse) and sum of its digits is an even number.)
Example: 121 – is a palindrome number
Sum of the digits – 1+2+1 = 4 which is an even number