I am trying to make a program that outputs a triangle and the program then should asks the user to enter the size of a triangle to print on the screen. After getting this number, the program should then print a triangle to the screen by printing a series of lines consisting of asterisks. Each line having one more asterisk than the previous line, up to the number entered by the user. After reaching the number entered by the user, on the next line, print one less asterisk and continue by decreasing the number of asterisks by one for each successive line.
For example:
If the user enters 3, then your program should display this:
*
**
***
**
*
If the user enters 6, then your program should display this:
*
**
***
****
*****
******
*****
****
***
**
*
Code:
System.out.println("How many asterisks do you want?");
line = kbd.nextInt();
printLine(line);
public static void printLine(int line) {
char number = 32;
for (int x = line; x > 0; x--)
{
System.out.print("*");
}
With printLine being my made up method for getting the users input. I dont know how to get the stars to go out to the right instand of just going down.
Please help!!!