Inverse Triangle Example in Java

In this example, I am attaching simple program about, Inverse Triangle Example in Java. The program were tested and shared in the post.

InverseTriangle.java

package com.javatraineronline;
import java.util.Scanner;
public class InverseTriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of Triangle Size");
int elements = sc.nextInt();
for (int j = 0; j < elements; j++) {
if (j != 0) {
for (int k = j; k > 0; k--) {
System.out.print(" ");
}
}
for (int i = elements - j; i > 0; i--) {
System.out.print("#");
}
System.out.println();
}
}
}

Output

[su_box title=”Output for InverseTriangle.java”]

##########
#########
########
#######
######
#####
####
###
##
#

[/su_box]

See also

Interview Java Porgrams

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *