Floyd’s triangle in java program

In the following example, we’ll create a program that prints Floyd Triangle using any character that is given as input from the user. The Program thus prints Floyd Triangle out of that character.

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

Source Code:

/* Program to print Floyd Triangle*/
import java.util.*;
class FloydTriangle
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,x=1;
System.out.println("Floyd Triangle: \n");




Enter Any Character: ?

 Enter Size Limit: 5
 Floyd Triangle: 


 Enter Any Character: $

 Enter Size Limit: 7
 Floyd Triangle: 


Report Error/ Suggestion

Related Posts:

CopyRight © 2020

CopyRight © 2020