in Education by
Analyse the given program segment and answer the following questions i) write the output of the program segment ii)how many times does the body of the loop gets execute for(int m=5 ; m<=20 ;m+=5) { if (m%3= = 0) break; else if (m%5= = 0) System.out.println(m) continue; } Please give me a perfect answer with understandable steps Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Hey Mate! Here’s the solution for your question: In the first turn, m = 5, which is lesser than 20. So, the condition returns true and hence the loop is executed. In the 1st iteration of the loop, the if condition returns false, since m % 3, i.e. 5 % 3 ≠ 0. Hence, the false block statements are executed. In the false block, the if condition returns true since 5 % 5 is equal to 0. So, m i.e. 5 is displayed and the loop is continued. In the second turn, m is still <20, so the 2nd iteration takes place. In the 2nd iteration, the if condition returns true, since 6 % 3 = 0. So the true block statement gets executed. In the true block, the break statement terminates the loop and hence the control moves out from the loop without further execution. So, the answers to the questions are as follows: i ) 5 ii ) 2 times Hope it Helps!

Related questions

0 votes
0 votes
0 votes
0 votes
    int n=10;int res=(n–+10>–n×5)?++n:n++ System.Out.println(res+”,”+n); what is the output Select the correct answer from above options...
asked Dec 30, 2021 in Education by JackTerrance
0 votes
    State the type of errors if any in the following statements: (i) switch ( 2 ); (ii) System.out.println(670/0); pls answer Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
    do you think the following two expression are the same if yes write the output if not justify your answer X=int(22/7) X=(22.0/7) Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    In Java, what will be the output of the following code and how? double x=2.9,y=2.5; (SOP is abbreviated form ... x),y)); Explain how Select the correct answer from above options...
asked Nov 28, 2021 in Education by JackTerrance
0 votes
    double x=0.5; System.out.println(Math.rint(x)); ….Plzz give me the output… Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    int fun(int n) { if(n!=0) { return n – fun(n-5); } else { return n; } } int main(){ int n = 20, z; z = fun(n); printf(“%d”, z); } Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    class Modulus { public static void main(String args[]) { double a = 25.64; int b = 25; a = a % 10; b = b % 10; ... (a + + b); } } Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
0 votes
    What is the output of the following: System. out. Println(“Time\n and \t tide waits for\”no man\””); pls answer Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
...