Home Tutorial Java Scjp Part5 SCJP Module-5 Question-6


Share on Google+Share on Google+
SCJP Module-5 Question-6
Posted on: July 12, 2010 at 12:00 AM
This program will test your understanding of while loop in Java and is helpful for SCJP exam.

Given a sample code:

1    public class Sample {
2    static int j=5;
3    public static void main(String args[]) {
4    while (j > 0) {
5    j--;
6    }
7    System.out.println(j);

What will be the result of above code ?

(1) 1
(2) 0
(3) 4
(4) The program compilation fails because of line number 2.




The variable j gets initialized to zero and therefore while loop does not get executed.


Related Tags for SCJP Module-5 Question-6:

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.

Posted on: July 12, 2010

Recommend the tutorial

Advertisements Advertisements