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
Give 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);
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:
13To 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++)
Define a class to accept a number and check whether it is an FDS Number or not. A number is called an FDS Number if the sum of the factorials of its digits equals the number itself.
Example 1:
Input: 145
Output: FDS Number [1! + 4! + 5! = 1 + 24 + 120 = 145]Example 2:
Input: 123
Output: Not an FDS Number [1! + 2! + 3! = 1 + 2 + 6 ≠ 123]import java.util.Scanner; class KboatFDSNum { static int fact(int d) { int f = 1; _______(1)_________ { _______(2)_________ } _______(3)_________ } public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); int num = in.nextInt(); int t = num, sum = 0; _______(4)_________ { _______(5)_________ _______(6)_________ _______(7)_________ } _______(8)_________ { _______(9)_________ } else { _______(10)_________ } } }