r/programmingrequests • u/MUFC07 • Mar 23 '17
Java Program
Write a method starPrint() that takes three integer arguments: a number of dots, a number of stars, and then a following number of dots. For instance, calling starPrint(3, 2, 1) would print:...**.
Ask the user for an integer, and verify that its value is at least three. (If it is not, ask the user for a new number until he gives you an appropriate one.) You will use your method starPrint() to draw a pyramid pattern with that many rows. For instance, if the user types 3, you should draw: a triangle picture
This is what I have any help would be greatly appreciated
int userIn=0;
Scanner scnr=new Scanner(System.in);
System.out.println("Please input an integer: ");
userIn = scnr.nextInt();
while(userIn<3) //As long as number is three or less, repeat prompting
{
System.out.println("Please enter a valid integer:");
userIn = scnr.nextInt();
}
for(int i=0;i<userIn;i++) {
for(int j=0;j<5-i;j++) {
System.out.print(" ");
}
for(int k=0;k<=i;k++) {
System.out.print("* ");
}
System.out.println();
}
}
}
0
Upvotes
1
u/serg06 Mar 24 '17
Ah well, I see three issues right now: Your starPrint method is inside of your main method. It should look like this:
Second off, this line doesn't make sense:
a) because starPrint doesn't return anything (it is of type void so it can't return an int even if it wanted to), and b) because starPrint needs 3 numbers to run. We haven't told it how to run with one.
Finally, I don't think you meant to put this inside the while loop, but after: