SCJP Module-5 Question-1

The program given below tests your understanding of 'do while' loop in core Java and helps you SCJp examination.

 
 

Share on Google+Share on Google+

SCJP Module-5 Question-1

Ads

The program given below tests your understanding of 'do while' loop in core Java and helps you SCJp examination.

Given a sample code:

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

What will be the result of above code ?

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

Answer:

(3)

Advertisements

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