I am trying to create a triangular pyramid of alternating characters "*" and "o", with the number of lines based on user input. The expected result that I am trying to achieve if the user enters "6" for the number of lines is:
*
*o*
*o*o*
*o*o*o*
*o*o*o*o*
*o*o*o*o*o*
The code I wrote for this:
String star = "*";
String circle = "o";
System.out.println("Please enter number of rows: ");
int rows = in.nextInt();
for (int i = 0; i < rows; i++){
for (int j = 0; j < rows-i; j++){
System.out.print(star);
}
for (int k = 0; k <= i; k++){
System.out.print(circle);
}
System.out.println();
}
However, the output from my code does not match the pyramid above. The output of my code with user input "6":
******o
*****oo
****ooo
***oooo
**ooooo
*oooooo
, -, , , , . , , , , .