Submitted by c-admin on Tue, 06/04/2019 - 21:58
Consider the following code for the main() method:
public static void main(String[] args) throws Exception{
int i = 1, j = 10;
do {
if (i++ > --j) continue;
} while (i < 5);
System.out.println("i=" + i + " j=" + j);
}
What will be the output when the above code is executed?
Select 1 option
A. i=6 j=6
B. i=5 j=6
C. i=5 j=5
D. i=6 j=5
E. None of these.
Submitted by c-admin on Tue, 06/04/2019 - 21:53
What will the following code print when compiled and run
public class TestClass {
public static void main(String[] args){
while(int k = 5; k<7){
System.out.println(k++);
}
}
}
Select 1 option
A. 5
6
B. 5
6
7
C. It will keep printing 5.
D. It will not compile.
E. It will throw an exception at run time.
Submitted by c-admin on Fri, 05/31/2019 - 04:19
Identify the valid for loop constructs assuming the following declarations:
Object o = null;
Collection c = //valid collection object.
int[][] ia = //valid array
Select 2 options
A. for(o : c){ }
B. for(final Object o2 :c){ }
C. for(int i : ia) { }
D. for(Iterator it : c.iterator()){ }
E. for(int i : ia[0]){ }
Submitted by c-admin on Fri, 05/31/2019 - 04:17
What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
int k = 2;
while(--k){
System.out.println(k);
}
} }
Select 1 option
A. 1
B. 1 0
C. 2 1
D. 2 1 0
E. It will keeping printing numbers in an infinite loop.
F. It will not compile.
Submitted by c-admin on Fri, 05/31/2019 - 04:14
What will the following code print?
void crazyLoop(){
int c = 0;
JACK: while (c < 8){
JILL: System.out.println(c);
if (c > 3) break JILL; else c++;
}
}
Select 1 option
A. It will not compile.
B. It will throw an exception at runtime.
C. It will print numbers from 0 to 8
D. It will print numbers from 0 to 3
E. It will print numbers from 0 to 4
Pages