Submitted by c-admin on Tue, 05/28/2019 - 22:11
What will the following code print when compiled and run:
public class TestClass {
public static void main(String[] args){
int k = 2;
do{
System.out.println(k);
}while(--k>0);
}
}
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 Tue, 05/28/2019 - 22:07
How many times will the line marked //1 be called in the following code?
int x = 10;
do{
x--;
System.out.println(x); // 1
}while(x<10);
Select 1 option
A. 0
B. 1
C. 9
D. 10
E. None of these.
Submitted by c-admin on Tue, 05/28/2019 - 22:05
What can you do to make the following code compile?
public class TestClass {
public static void main(String[] args) {
int[] values = { 10, 20, 30 };
for( /* put code here */ ){
}
}
}
Select 2 options
A. int k : values
B. int k in values
C. int k; k<0; k++
D. ;;
E. ; k<values.length;k++
Submitted by c-admin on Tue, 05/28/2019 - 21:59
Which of these statements are valid when occurring by themselves?
Select 3 options
A. while ( ) break ;
B. do { break ; } while (true) ;
C. if (true) { break ; } (When not inside a switch block or a loop)
D. switch (1) { default : break; }
E. for ( ; true ; ) break ;
Submitted by c-admin on Tue, 05/28/2019 - 21:55
Using a break in a while loop causes the loop to break the current iteration and start the next iteration of the loop.
Select 1 option
A. True
B. False
Pages