redict the output. public class Test { public static void main(String args[]) { int a = 2, b = 0; for ( ; b < 20; ++b) { if (b % a == 0) continue; else if (b == 10) break; else System.out.print(b + " "); } }
Question
redict the output. public class Test { public static void main(String args[]) { int a = 2, b = 0; for ( ; b < 20; ++b) { if (b % a == 0) continue; else if (b == 10) break; else System.out.print(b + " "); } }
Solution
The code is written in Java. It initializes two integer variables, a and b, with values 2 and 0 respectively. Then it enters a loop which will continue until b is less than 20.
In each iteration of the loop, it first checks if b is divisible by a (i.e., b % a == 0). If it is, then it skips the rest of the loop for this iteration and goes back to the start of the loop (because of the continue statement).
If b is not divisible by a, then it checks if b is equal to 10. If it is, then it breaks out of the loop entirely (because of the break statement).
If b is neither divisible by a nor equal to 10, then it prints out the value of b followed by a space.
So, the output of this code will be the numbers from 1 to 20 that are not divisible by 2 and less than 10, each followed by a space. Specifically, the output will be: 1 3 5 7 9 .
Similar Questions
What is the output of the programme below?public static void main(String[] args) { int x = 0; while (x < 10) { if (x & 2 == 0) { System.out.print(x + “ “); } x++; }}
Determine output:public class Test{ public static void main(String args[]){ int i, j; for(i=1, j=0;i<10;i++) j += i; System.out.println(i); }}1011920
public class Compute {public static void main (string args [ ]){int result, x ;x = 1 ;result = 0;while (x < = 10) {if (x%2 == 0) result + = x ;+ + x ;}System.out.println(result) ;}}
.What will be the output of the program ?public class Test { public static void main(String [] args) { signed int x = 10; for (int y=0; y<5; y++, x--) System.out.print(x + ", "); }}10, 9, 8, 7, 6,9, 8, 7, 6, 5,Compilation fails.An exception is thrown at runtime.
What will be the output?public class Test{ public static void main(String args[]){ int i = 1; do{ i--; }while(i > 2); System.out.println(i); }}12-10
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.