public class While {     
pub

Loading

Practice Flow Control –

public class While {     
public void loop() {
int x= 0;
while ( 1 ) { /* Line 4 */
System.out.print("x plus one is " + (x + 1)); /* Line 5 */
}
}
}

Which statement is true?

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

int i = 1, j = 10;  
do {
if(i++ > --j) /* Line 4 */{
continue;
}
} while (i < 5);
System.out.println("i = " + i + "and j = " + j); /* Line 9 */

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class Test {     
public static void main(String [] args) {
int I = 1;
do while ( I < 1 )
System.out.print("I is " + I);
while ( I > 1 ) ;
}
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

int i = 1, j = 10;  
do {
if(i > j) {
break;
}
j--;
}
while (++i < 5);
System.out.println("i = " + i + " and j = " + j);

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class ExamQuestion6 {     
static int x;
boolean catch() {
x++;
return true;
}
public static void main(String[] args) {
x=0;
if ((catch() | catch()) || catch())
x++;
System.out.println(x);
}
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class ObjComp {     
public static void main(String [] args ) {
int result = 0;
ObjComp oc = new ObjComp();
Object o = oc;
if (o == oc)
result = 1;
if (o != oc)
result = result + 10;
if (o.equals(oc) )
result = result + 100;
if (oc.equals(o) )
result = result + 1000;
System.out.println("result = " + result);
}
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

int I = 0; 
label: if (I < 2) {
System.out.print("I is " + I);
I++;
continue label;
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

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?


			  		

Loading

Practice 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?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

lass Test {     
public static void main(String [] args) {
int I = 0;
outer: while (true) {
I++;
inner: for (int j = 0; j < 10; j++) {
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);
}
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class If1 {     
static boolean b;
public static void main(String [] args) {
short hand = 42;
if ( hand < 50 && !b ) /* Line 7 */
hand++;
if ( hand > 50 ); /* Line 9 */
else if ( hand > 40 ) {
hand += 7;
hand++;
}
else
--hand;
System.out.println(hand);
}
}

 

public void test(int x) {
int

Loading

Practice Flow Control –

public void test(int x) {
int odd = 1;
if(odd) {/* Line 3 */
System.out.println("odd");
}
else {
System.out.println("even");
}
}

Which statement is true?

What will be the output of the program?


			  		

Loading

Practice Flow Control –

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 < 3; z++) {
switch (z) {
case y: System.out.print("0 "); /* Line 11 */
case x-1: System.out.print("1 "); /* Line 12 */
case x: System.out.print("2 "); /* Line 13 */
}
}
}
}