Write a Java Program To Print Floyd's Triangle


package com.java2study;

import java.util.Scanner;

public class FloydsTraingle {
/*
* 1
* 2 3
* 4 5 6
* 7 8 9 10
*/

public static void main(String[] args) {

int number = 1;
//accept the user input From The KeyBoard
Scanner scanner = new Scanner(System.in);
System.out.println("Enter The NumberOf Rows:");
int noofrows = scanner.nextInt();
for(int r = 1;r<=noofrows;r++){
for(int c = 1;c<=r;c++){
System.out.print(number+" ");
number++;

}
System.out.println();

}


}

}

output


Enter The NumberOf Rows:
1
1
----------------
Enter The NumberOf Rows:
2
1
2 3
-------
Enter The NumberOf Rows:
3
1
2 3
4 5 6
-----
Enter The NumberOf Rows:
4
1
2 3
4 5 6
7 8 9 10

No comments:

Post a Comment