Java program to print inverted floyd's triangle of any character
Written by
In the following example, we’ll create a program that prints an Inverted Floyd Triangle using any character that is given as input by the user. The Program thus prints Inverted Floyd Triangle out of that character.
To print an inverted Floyd triangle, we can follow the usual logic for generating a Floyd triangle, but instead of using a loop control variable to print the characters, we can use the input character. This will create an inverted triangle pattern using the input character.
Source Code:
import java.util.*;
class InvFloydTriangle {
public static void main() {
Scanner inp = new Scanner(System.in);
System.out.print("\nEnter Any Character: ");
char c = (inp.nextLine()).charAt(0);
System.out.print("\nEnter Size Limit: ");
int n = inp.nextInt();
int i, j, k;
System.out.println("Inverted Floyd Triangle: \n");
for (i = n; i >= 1; i--) {
for (j = 1; j <= i; j++) {
System.out.print(c);
}
System.out.println();
}
}
}
Output:
Enter Any Character: @
Enter Size Limit: 5
Inverted Floyd Triangle:
@@@@@
@@@@
@@@
@@
@
Enter Any Character: !
Enter Size Limit: 3
Inverted Floyd Triangle:
!!!
!!
!