Share on Google+Share on Google+

SCJP Module-2 Question-13

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 :


Explanation :

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


Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.