Submitted by c-admin on Tue, 05/28/2019 - 21:50
What will be the output if you run the following program?
public class TestClass{
public static void main(String args[]){
int i;
int j;
for (i = 0, j = 0 ; j < 1 ; ++j , i++){
System.out.println( i + " " + j );
}
System.out.println( i + " " + j );
}
}
Select 1 option
A. 0 0 will be printed twice.
B. 1 1 will be printed once.
C. 0 1 will be printed followed by 1 2.
D. 0 0 will be printed followed by 1 1.
E. It will print 0 0 and then 0 1.
Submitted by c-admin on Tue, 05/28/2019 - 21:43
What will the following program print?
class LoopTest{
public static void main(String args[]) {
int counter = 0;
outer:
for (int i = 0; i < 3; i++) {
middle:
for (int j = 0; j < 3; j++) {
inner:
for (int k = 0; k < 3; k++) {
if (k - j > 0) {
break middle;
}
counter++;
}
}
}
System.out.println(counter);
}
}
Select 1 option
A. 2
B. 3
C. 6
D. 7
E. 9
Pages