Java Programs

Java Program for Triangle Part 1

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

Java Program for Triangle Part 1 :

Triangle_Down_LeftToRight.java
package com.onlinetutorialspoint.patterns;
import java.util.Scanner;
public class Triangle_Down_LeftToRight {
    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();
        for (int i = 1; i & lt; = size; i++) {
            for (int j = 1; j & lt; = size; j++) {
                if (j & lt; i) {
                    System.out.print(" ");
                } else {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }
}

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

Java Program for Triangle

Happy Learning :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment