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
Submitted by c-admin on Fri, 05/31/2019 - 04:13
What will the following program snippet print?
int i=0, j=11;
do{
if(i > j) { break; }
j--;
}while( ++i < 5);
System.out.println(i+" "+j);
Select 1 option
A. 5 5
B. 5 6
C. 6 6
D. 6 5
E. 4 5
Submitted by c-admin on Fri, 05/31/2019 - 04:06
What will the following code print?
void crazyLoop(){
int c = 0;
JACK: while (c < 8){
JILL: System.out.println(c);
if (c > 3) break JACK; 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