Computer Applications
To execute a loop 5 times, which of the following is correct?
Java Iterative Stmts
1 Like
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 > 45becomes 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 < 57becomes 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 >= 45becomes 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.
Answered By
3 Likes
Related Questions
Write a program in Java to find the Fibonacci series within a range entered by the user.
Sample Input:
Enter the minimum value: 10
Enter the maximum value: 20Sample Output:
13Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);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