A pattern of Lloyd Triangle in Java
Program:-
// Q1. Write a program in Java find Patten of trinagle size
import java.util.Scanner;
class FloydTrangle{
public static void main(String arg[]){
int num =1 ;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows of flyod's trinagle you want:");
int number = sc.nextInt();
System.out.println("Flyod's trinagle: - ");
for(int i= 1; i <=number; i++ ){
for(int j = 1; j<=i; j++){
System.out.print(num+" "); //Print Numeric Number
// System.out.print("*"); //Print Stick Pattern
num++;
}
System.out.println();
}
}
}
Output:
PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\allpraque> javac 31q_FlyodTriangle.java
PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\allpraque> java FloydTrangle
Enter the number of rows of flyod's trinagle you want:
5
Flyod's trinagle: -
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Comments