import java.util.Scanner;
public class FloydsTriangle {
public static void main(String[] args) {
Scanner myScanner=new Scanner(System.in);
System.out.print("Enter the number of rows of Floyd's triangle you want : ");
int n=myScanner.nextInt();
int num=1;
System.out.print("The Floyd's triangle is : \n");
for (int i = 1; i <=n; i++) {
for (int j = 1; j <=i; j++) {
System.out.print(num+" ");
num++;
}
System.out.println();
}
}
}
//Enter the number of rows of Floyd's triangle you want : 5
//The Floyd's triangle is :
//1
//2 3
//4 5 6
//7 8 9 10
//11 12 13 14 15
public class FloydsTriangle {
public static void main(String[] args) {
Scanner myScanner=new Scanner(System.in);
System.out.print("Enter the number of rows of Floyd's triangle you want : ");
int n=myScanner.nextInt();
int num=1;
System.out.print("The Floyd's triangle is : \n");
for (int i = 1; i <=n; i++) {
for (int j = 1; j <=i; j++) {
System.out.print(num+" ");
num++;
}
System.out.println();
}
}
}
//Enter the number of rows of Floyd's triangle you want : 5
//The Floyd's triangle is :
//1
//2 3
//4 5 6
//7 8 9 10
//11 12 13 14 15
No comments:
Post a Comment