Cloning a 2-D array
Predict the outputMedium-HardJava onlyAsked in: Capgemini
public class Main {
public static void main(String[] args) {
int[][] grid = {{1, 2}, {3, 4}};
int[][] copy = grid.clone();
copy[0][0] = 9;
copy[1] = new int[] {7, 7};
System.out.println(grid[0][0] + " " + grid[1][0]);
System.out.println(copy[0][0] + " " + copy[1][0]);
}
}
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.