Java Programming :: Flow Control
-
What will be the output of the program?
int x = 3; int y = 1; if (x = y) /* Line 3 */ { System.out.println("x =" + x); }
-
What will be the output of the program?
Float f = new Float("12"); switch (f) { case 12: System.out.println("Twelve"); case 0: System.out.println("Zero"); default: System.out.println("Default"); }
-
What will be the output of the program?
int i = 0;
while(1){
if(i == 4)
{
break;
}
++i;}
System.out.println("i = " + i);
-
What will be the output of the program?
public class Delta { static boolean foo(char c) { System.out.print(c); return true; } public static void main( String[] argv ) { int i = 0; for (foo('A'); foo('B') && (i 2); foo('C')) { i++; foo('D'); } } }
-
What will be the output of the program?
for(int i = 0; i 3; i++) { switch(i) { case 0: break; case 1: System.out.print("one "); case 2: System.out.print("two "); case 3: System.out.print("three "); } } System.out.println("done");
-
What will be the output of the program?
public class Test
{
public static void main(String args[])
{
int i = 1, j = 0;switch(i)
{
case 2: j += 6;
case 4: j += 1;
default: j += 2;
case 0: j += 4;
}
System.out.println("j = " + j);}
}
-
What will be the output of the program?
boolean bool = true; if(bool = false) /* Line 2 */ { System.out.println("a"); } else if(bool) /* Line 6 */ { System.out.println("b"); } else if(!bool) /* Line 10 */ { System.out.println("c"); /* Line 12 */ } else { System.out.println("d"); }
-
What will be the output of the program?
public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z 4; z++) { switch (z) { case x: System.out.print("0 "); default: System.out.print("def "); case x-1: System.out.print("1 "); break; case x-2: System.out.print("2 "); } } } }
-
What will be the output of the program?
int i = 0, j = 5; tp: for (;;) { i++; for (;;) { if(i > --j) { break tp; } } System.out.println("i =" + i + ", j = " + j);
-
What will be the output of the program?
int I = 0; label: if (I 2) { System.out.print("I is " + I); I++; continue label; }