Q:

How To List Numbers on a Reverse Triangle on Java

How can I print out Triangles with Listed numbers using for loops. So far I manage to successfully print it like this:
1  X
2  X X
3  X X X
4  X X X X
5  X X X X X

My next assignment is the same except I must print the "X" in reverse order by the user like this:
1  X X X X X
2  X X X X
3  X X X
4  X X
5  X

I manage to make my code print the triangles but the number is not in the right place. The printout is this:
  5
 X X X X X  4
 X X X X  3
 X X X  2
 X X  1
 X  0

Is there something wrong that I am doing? Is there something else I need to do? Here is my current code:
public class problem4
{
    private static Scanner input;
    public static void main(String[] args)  
    {
        input = new Scanner(System.in);
        System.out.print("Enter a Number: ");
        int n = input.nextInt();
        for (int i = n; i >= 0; i--)
        {
            System.out.println("  " + i);
            for (int j = i; j > 0; j--)
            {
                System.out.print(" X");
            }
        }
        System.out.println("");
    }
}

A:

Modify your code like this:
import java.util.Scanner;

public class problem4
{
    private static Scanner input;
    public static void main(String[] args)  
    {
        input = new Scanner(System.in);
        System.out.print("Enter a Number: ");
        int n = input.nextInt();
        for (int i = n; i > 0; i--)
        {
            System.out.print("  " + (n + 1 - i));
            for (int j = i; j > 0; j--)
            {
                System.out.print(" X");
            }
            System.out.println();
        }

    }
}

Besides that, please follow the java naming conventions.

Class names should be nouns, in mixed case with the first letter of
  each internal word capitalized.

