Looping Constructs

Quiz Guidelines

 

Multiple Choice Question

QID: 
164

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.

Multiple Choice Question

QID: 
163

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.

Multiple Choice Question

QID: 
162

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++

Multiple Choice Question

QID: 
161

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 ;

True or False

QID: 
160

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