0

explain how it is working and what is arr[i] = new int[i + 1];

public static void main(String args[]) { int m = 3; int arr[][] = new int[m][]; for(int i = 0; i < arr.length; i++) { arr[i] = new int[i + 1]; for(int j = 0; j < arr[i].length; j++) { arr[i][j] = i; System.out.print(arr[i][j] + " "); } System.out.println(); } } }

15th Apr 2021, 12:45 PM
Sachin Saxena
Sachin Saxena - avatar
3 Answers
0
i learnt c lang already now i m learning java i learnt about loops in c but this is something different i dont understand whats happening here and how output is get calculated
15th Apr 2021, 12:57 PM
Sachin Saxena
Sachin Saxena - avatar
0
arr[i] = new int[i + 1]; //initializing column size as i+1 of elements, for i'th row
15th Apr 2021, 2:54 PM
Jayakrishna 🇼🇳
- 1
But values of i one by one if u know how to use loop u can easily calculate
15th Apr 2021, 12:49 PM
A S Raghuvanshi
A S Raghuvanshi - avatar