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.
(B)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.