I have searched for this and found many similiar questions. The trick here is to not make the exact same image as below. The triangles need to be seperate.
Write a java application that displays the following patterns separately one below the other.
Use for loops to generate the patterns. There are 4 Triangle patterns.
All asterisks (*) should be printed by a single statement of the form System.out.print('*');
* ********** ********** *
** ********* ********* **
*** ******** ******** ***
**** ******* ******* ****
***** ****** ****** *****
****** ***** ***** ******
******* **** **** *******
******** *** *** ********
********* ** ** *********
********** * * **********
I have figured out the 1st triangle and the third triangle. Although I don't completely understand why the third triangle works. I can't seem to figure out the 2nd and 4th. Here is what I have:
//This program display 4 triangle patterns using for loops
//Use the Scanner class to create an object to read input from system.in
public class Triangle3 {
public static void main (String[] args){
/*Create for loop for triangle 1
/* loop 10 times
*/
int row;
// maximum number of rows
int maxRows = 10;
//create a loop
for (row = 1; row <= maxRows; row++) {
//print *
int firstTri;
for (firstTri = 1; firstTri <= row; firstTri++){
System.out.print ("*");
}
//print a new line
System.out.println();
}
row = 1;
maxRows = 10;
//Create for loop for triangle 3
for (row = 1; row <= maxRows; row++) {
//print *
int thirdTri;
for (thirdTri = 10; thirdTri >= row; thirdTri--){
System.out.print ("*");
}
//print a new line
System.out.println();
}
}
}
