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 > 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.
Answered By
1 Like
Related Questions
To execute a loop 10 times, which of the following is correct?
- for (int i=11;i<=30;i+=2)
- for (int i=11;i<=30;i+=3)
- for (int i=11;i<20;i++)
- for (int i=11;i<=21;i++)
Convert the following for loop segment to an exit-controlled loop.
for (int x = 1, y = 2; x < 11; x += 2, y += 2) { System.out.println(x + "\t" + y); }
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:
13Write a program to input a number and find whether the number is an emirp number or not. A number is said to be emirp if the original number and the reversed number both are prime numbers.
For example, 17 is an emirp number as 17 and its reverse 71 are both prime numbers.