Submitted by c-admin on Fri, 05/31/2019 - 04:04
What will be the result of attempting to compile and run the following program?
class TestClass{
public static void main(String args[]){
int i = 0;
for (i=1 ; i<5 ; i++) continue; //(1)
for (i=0 ; ; i++) break; //(2)
for ( ; i<5?false:true ; ); //(3)
}
}
Select 1 option
A. The code will compile without error and will terminate without problems when run.
B. The code will fail to compile, since the continue can't be used this way.
C. The code will fail to compile, since the break can't be used this way
D. The code will fail to compile, since the for statement in the line 2 is invalid.
E. The code will compile without error but will never terminate.
Submitted by c-admin on Fri, 05/31/2019 - 04:01
Consider the following code:
public static void main(String[] args) {
int[] values = { 10, 30, 50 };
for( int val : values ){
int x = 0;
while(x<values.length){
System.out.println(x+" "+val);
x++;
}
}
}
How many times is 2 printed out?
Select 1 option
A. 0
B. 1
C. 2
D. 3
Submitted by c-admin on Fri, 05/31/2019 - 03:49
What will be the output when the following program is run?
public class TestClass{
public static void main(String args[]){
int i;
int j;
for (i = 0, j = 0; j < i; ++j, i++){
System.out.println(i + " " + j);
}
System.out.println(i + " " + j);
}
}
Select 1 option
A. 0 0 will be printed twice.
B. 0 0 will be printed once.
C. It will keep on printing 0 0
D. It will not compile.
E. It will print 0 0 and then 0 1.
Submitted by c-admin on Fri, 05/31/2019 - 03:44
What will the following code print when compiled and run?
class Test{
public static void main(String args[]){
int c = 0;
A: for(int i = 0; i < 2; i++){
B: for(int j = 0; j < 2; j++){
C: for(int k = 0; k < 3; k++){
c++;
if(k>j) break;
}
}
}
System.out.println(c);
}
}
Select 1 option
A. 7
B. 8
C. 9
D. 10
E. 11
Submitted by c-admin on Fri, 05/31/2019 - 03:42
What will the following program print?
class Test{
public static void main(String args[]){
int i=0, j=0;
X1: for(i = 0; i < 3; i++){
X2: for(j = 3; j > 0; j--){
if(i < j) continue X1;
else break X2;
}
}System.out.println(i+" "+j);
} }
Select 1 option
A. 0 3
B. 0 2
C. 3 0
D. 3 3
E. 2 2
Pages