I have to make a number "triangle that goes like this, using the number 5 as an example:
____1
___21
__321
_4321
54321
except the underscores are spaces.
Here is what I have:
import java.util.Scanner;
public class loop1
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.print("Enter a number (1-9): ");
int n = stdIn.nextInt();
while (n < 1 || n > 9)
{
System.out.print("Error. Enter a number (1-9): ");
n = stdIn.nextInt();
}
System.out.println("You entered " + n + ". Have a nice day.");
int j=1, k=1;
while (j<=n)
{
k = 1;
while (k<=n-j)
{
System.out.print(" ");
k++;
}
k = 1;
while (k<=j)
{
System.out.print(k);
k++;
}
System.out.print("\n");
j++;
}
}
}
and that produces:
Enter a number (1-9): 5
You entered 5. Have a nice day.
____1
___12
__123
_1234
12345
except the underscores are spaces.
So my question is, what do I change to have the ones go in the last column?? I've tried changing so many things!