diff --git a/FloydsTriangle.java b/FloydsTriangle.java new file mode 100644 index 0000000..fa456bc --- /dev/null +++ b/FloydsTriangle.java @@ -0,0 +1,42 @@ +import java.util.Scanner; +/* +ques: Floys triange? +"Floyd's Triangle," which is a right-angled triangular array of natural numbers. +In this triangle, each row contains consecutive natural numbers, starting from 1. + + 1 + 2 3 + 4 5 6 + + */ + +public class FloydsTriangle { + public static void main(String[] args) { + System.out.print("Enter the number of row:"); + Scanner sc = new Scanner(System.in); + int n=sc.nextInt(); + + int x=1; + //outer loop + for(int i=1; i<=n; i++){ + for(int j=1; j<=i; j++){ + System.out.print(x+" "); + x++; + } + System.out.println(); + } + + } +} + +/* + OUTPUT: + +Enter the number of row:5 +1 +2 3 +4 5 6 +7 8 9 10 +11 12 13 14 15 + +*/