Ask the user to enter a number between 4 and 20. If the user enters a number outside that range ask them for the number again. Based on the number the user enters, print a triangle of stars as in the following example:
If the user enters 5, your program would print the following:
*
**
***
****
*****
(except the alignment is to the right)
so basically..
____*
___**
__***
_****
*****
without the _
So far, I've got the error checking alright, but I don't really know where to start with for the stars.
public static void main(String [] args)
{
Scanner k = new Scanner(System.in);
System.out.println("Please enter a number between 4 and 20");
int num = k.nextInt();
while(num < 4 || num > 20)
{
System.out.println("Oops! Your number is not between 4 and 20, enter another one");
num = k.nextInt();
}
}
I'm assuming it involves a for loop, with a System.out.print(" "); System.out.print("*"); and a System.out.println("");
but any more than that I'm not sure..