Question: public static char [ ] [ ] getTriangles ( int rows ) { char [ ] [ ] triangle = new char [ rows ]

public static char[][] getTriangles(int rows){
char[][] triangle = new char[rows][rows *2-1];
for (int i =0; i rows; i++){
for (int j =0; j rows *2-1; j++){
if (j == rows -1- i || j == rows -1+ i){
triangle[i][j]='/';
} else if (j > rows -1- i && j rows -1+ i){
triangle[i][j]='_';
} else {
triangle[i][j]='';
}
}
}
return triangle;
} This doesnt make the correct pattern. The correct pattern is provided in the image. Triangle Pattern
A Triangle pattern with 1 row contains 2 lines with 4 characters on each line. The first line contains a
space followed by a forward slash, a backslash, and a space. The second line contains a forward
slash followed by 2 underscores followed by a backslash. For example,
A Triangle pattern with 2 rows is made up of 3 lines with 6 characters on each line and is formatted
as shown below. The first line contains 2 spaces, followed by a forward slash, backslash, and 2
spaces. The second line contains a space, followed by a forward slash, 2 underscores, a backslash,
and a space. The third line contains a forward slash followed by 4 underscores and a backslash.
A Triangle pattern with 3 rows is made up of 4 lines with 8 characters on each line and is formatted
as shown below.
 public static char[][] getTriangles(int rows){ char[][] triangle = new char[rows][rows *2-1];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!