Hello, I have been struggling with this program for a while and was wondering if anyone could help.
I am trying to make a program where the user inputs an int 0-9 and then it will print out something like this:
if user input=1 if user input = 3 I hope you guys get what im trying to say. so far i have:
1 **1
*21
321
import java.util.Scanner;
public class Lab07 {
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
int x;
System.out.println("Enter a number 1-9: ");
x = stdIn.nextInt();
while (x <=0 || x>=10)
{
System.out.println("Please enter a number 1-9: ");
x = stdIn.nextInt();
}
int i,j,k;
for (i=1; i<= x;i++)
{
for (j=1;j<=x-i;j++)
{
System.out.print("*");
}
for (k=x-i;k<=9;k++)
{
System.out.print(k);
}
System.out.println();
}
stdIn.close();
}
}
THANKS!!!