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

 
 

Share on Google+Share on Google+
SCJP Module-5 Question-8
Posted on: July 12, 2010 at 12:00 AM
Advertisement
The program given below will test your understanding of for loops in Java and it is also very useful for SCJP exam.

Given a sample code:

1    public class Test {
2    public static void main(String args[]) {
3    int i, j ;
4    for (i = 0; i < 3; i++) {
5    for (j = 1; j < 4; j++) {
6    i %= j;
7    System.out.print(j);
}}
}}

What will be the result of above code ?

(1) 1 2 3
(2) 1 1 2
(3) Repeatedly print 123 and cause infinite loop.
(4) The program compilation fails because of line number 2.

Answer:

(3)

Advertisement

Related Tags for SCJP Module-5 Question-8:


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
 

 

 

DMCA.com