Computer Applications
Analyze the given program segment and answer the following questions:
- Write the output of the program segment.
- How many times does the body of the loop gets executed ?
for(int m = 5; m <= 20; m += 5)
{ if(m % 3 == 0)
break;
else
if(m % 5 == 0)
System.out.println(m);
continue;
}
Java Iterative Stmts
ICSE 2016
75 Likes
Answer
Output
5
10
Loop executes 3 times.
Below dry run of the loop explains its working.
| m | Output | Remarks |
|---|---|---|
| 5 | 5 | 1st Iteration |
| 10 | 5 10 | 2nd Iteration |
| 15 | 5 10 | 3rd Iteration — As m % 3 becomes true, break statement exists the loop. |
Answered By
35 Likes
Related Questions
Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]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
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:
13