Question: Try creating the triangular array from the previous section into a simple class or in jshell. Heres one way: Now expand that code to print
Try creating the triangular array from the previous section into a simple class or in jshell. Here’s one way:
![int[][] triangle = new int[5][]; for (int i = 0; i < triangle.length; i++) { triangle[i] = new int [i + 1];](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1704/1/8/8/0276593d87b425441704188027772.jpg)
Now expand that code to print the contents of triangle to the screen. To help, recall that you can print the value of an array element with the System.out.println() method:
![]()
Your output will probably be a long, vertical line of numbers like this:
0
1
2
2
3
4
3
4
5
6
4
5
6
7
8
int[][] triangle = new int[5][]; for (int i = 0; i < triangle.length; i++) { triangle[i] = new int [i + 1]; for (int j = 0; j < i + 1; j++) triangle[i][j] = i + j; }
Step by Step Solution
3.36 Rating (162 Votes )
There are 3 Steps involved in it
Heres how you can expand the given code to print the contents of the triangle array public class Tri... View full answer
Get step-by-step solutions from verified subject matter experts
