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

 
 

Share on Google+Share on Google+
SCJP Module-5 Question-11
Posted on: July 22, 2010 at 12:00 AM
Advertisement
The Sample program given below will test your understanding about the nested loops in Java.

Given a sample code:

1    import java.util.ArrayList;

2    public class Test2 {
3    public static void main(String[] args) {
4    ArrayList<Integer> numbers = new ArrayList<Integer>();
5    for (int i = 1; i <= 3; i++) {
6    for (int j = 1; j <= 3; j++) {
7    int value = i * 2 / 2;
8    {Integer intObj = new Integer(value); numbers.add(intObj);}
    } }
9    { System.out.println(numbers); }
    }}

What will be result when compiled and run?

(A)  [1, 2, 3, 1, 2, 3, 1, 2, 3]
(B)  [1, 1, 1, 2, 2, 2, 3, 3, 3]
(C)  Compilation error at line no-8. 
(D)  Compilation error at line no-9. 

Answer:

(B)

Advertisement

Related Tags for SCJP Module-5 Question-11:


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 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com