Hey guys and gals I need alittle help. i have an assignment that needs to print a certian number of stairs according to a user input.
Example program run (user input is in bold):
Please enter the number of rows: 4
Please enter the number of stars in row 1: 8
Please enter the number of stars in row 2: 2
Please enter the number of stars in row 3: 4
Please enter the number of stars in row 4: 1
********
**
****
*
this is my code so far :
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int rows;
Scanner keyboard = new Scanner(System.in);
//print splash screen
System.out.println("Welcome to Star Shapes ...");
System.out.println("\t... a program which lets you draw star shapes\n" +
"\t First enter the number of rows (1-10) then,\n" +
"\t Enter the number of stars for each row (1-10)\n" +
"\t Okay lets start:\n");
System.out.print("How many rows would you like ? ");
rows = keyboard.nextInt();
if (rows > 10) {
System.out.println("you can only have a max of 10 rows try again");
} else if (rows < 1) {
System.out.println("you have to have at least 1 row try again");
} else if (rows >= 1) {
if (rows <= 10) {
System.out.print("Please enter the number of stars in row 1..");
int row1 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 2..");
int row2 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 3..");
int row3 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 4..");
int row4 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 5..");
int row5 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 6..");
int row6 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 7..");
int row7 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 8..");
int row8 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 9..");
int row9 = keyboard.nextInt();
System.out.print("Please enter the number of stars in row 10..");
int row10 = keyboard.nextInt();
int[] shapeArray; // declares an array of integers
shapeArray = new int[10]; // allocates memory for 10 integers
shapeArray[0] = row1; // initialize first element
shapeArray[1] = row2; // initialize second element
shapeArray[2] = row3; // etc.
shapeArray[3] = row4;
shapeArray[4] = row5;
shapeArray[5] = row6;
shapeArray[6] = row7;
shapeArray[7] = row8;
shapeArray[8] = row9;
shapeArray[9] = row10;
for (int i = 0; i < rows; i++) {
for (int countt = 0; countt < shapeArray[i]; countt++) {
String printString = "*";
System.out.print(printString);
}
System.out.println((shapeArray[i]));
}
}
}
}
}
and here is my output:
Welcome to Star Shapes ...
... a program which lets you draw star shapes
First enter the number of rows (1-10) then,
Enter the number of stars for each row (1-10)
Okay lets start:
How many rows would you like ? 5
Please enter the number of stars in row 1..3
Please enter the number of stars in row 2..7
Please enter the number of stars in row 3..2
Please enter the number of stars in row 4..9
Please enter the number of stars in row 5..4
Please enter the number of stars in row 6..1
Please enter the number of stars in row 7..1
Please enter the number of stars in row 8..1
Please enter the number of stars in row 9..1
Please enter the number of stars in row 10..1
***3
*******7
**2
*********9
****4
everything works great expect my print statement continue after the number of rows are declared. in this example its 5 so there is no need for 6 7 8 ect.. i would love it to say after the fifth row have a statement that says "hit return to draw your stars" and then after that print the stars.
A few more minds on this would help a lot.
Thanks !!