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.

The basic idea is to first implement the logic of Inverted Floyd Triangle as usual and replace the Loop Control Variable that originally prints, with the input Character.

Source Code:

/* Program to print Inverted Floyd Triangle*/
import java.util.*;
class InvFloydTriangle
{
public static void main()
{
Scanner inp=new Scanner(System.in);
System.out.print("\n Enter Any Character: ");
char c=((inp.nextLine()).charAt(0));
System.out.print("\n Enter 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: 

!!!
!!
!

[yuzo_views]



CopyRight © 2019

CopyRight © 2019