SCJP Module-2 Question-13


 

SCJP Module-2 Question-13

The Program given below checks and helps the understanding of while loops in Java programming.

The Program given below checks and helps the understanding of while loops in Java programming.
What would be the output after executing following code :

public class Example13 {
public static void main(String[] args) throws Exception {
int a = 30;
while (a) {
System.out.print("value:" + a--);
}
}
}

What would be the output after executing given above code :

1. Compile error

2.  30 29,.....untill 1

3.  1 2 3.....untill 30

4.  no output

Answer :

(1)

Explanation :

'While' statement should contain a 'Boolean' value ,'condition' or 'expression' , whose outcome must be of  type Boolean.

Ads