Program to Generate Floyd triangle example in java.
/** * Program to generate Floyd triangle example in java. * @author W3schools360 */ public class FloydTriangle { static void generateFloydTriangle(int rows){ int num = 1; //Logic to generate Floyd's triangle. for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(num + " "); num++; } System.out.println(); } } public static void main(String args[]){ //method call generateFloydTriangle(5); } }
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Please follow and like us: