In this tutorials, we are going write a Java Program For Triangle Part 4 to create a below. This is a Part 4  of the complete example. You can follow the complete 4 parts to complete the entire examples.

Java program for Triangle Part – 4 :

Triangle_Top_RightToLeft.java
package com.onlinetutorialspoint.patterns;
import java.util.Scanner;

/*
 *     *
 *    **
 *   ***
 *  ****
 * *****
 *      
 */

public class Triangle_Top_RightToLeft {
    public static void main(String args[]) {
        /* Getting the input from keyboard */
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the size of Triangle");
        int size = scanner.nextInt();
        int spaces = size - 1;

        for (int i = 1; i <= size; i++) {
            for (int k = 1; k <= spaces; k++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
            spaces = spaces - 1;
        }

    }
}

By running the above Java program, you can get the below shape.

Output :

Terminal

javac  Triangle_Top_RightToLeft.java
java  Triangle_Top_RightToLeft

Java Program for Triangle Part - 4

Happy Learning 🙂