Java Program to Display Floyd’s Triangle Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 7 Likes Like Report Floyd’s triangle is a triangle with first natural numbers. It is the right arrangement of the numbers/values or patterns. Basically, it is a left to right arrangement of natural numbers in a right-angled triangle Illustration: Suppose if no of rows to be displayed is 5 then the desired output should display 5 rows as: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Algorithm: Initialization of variablesCreate variables in memory holding rows and columns.Create and initialize variable holding patterns or values to be displayed.Traversing over rows and columns using nested for loops.Outer loop for rows.Inner loop for columns in the current row.Dealing with variable holding dynamic values as per execution as initialized outside nested loops.If values are to be displayed, increment this variable inside the loop for rows and outside loop for columns.If patterns are to be displayed, assign the character outside loop while creation and no alternation of holder value in any of loops.Implementation: Floyd’s Triangle Example Java // Java program to display Floyd's triangle // Importing Java libraries import java.util.*; // Main class class GFG { // Main driver method public static void main(String[] args) { // No of rows to be printed int n = 5; // Creating and initializing variable for // rows, columns and display value int i, j, k = 1; // Nested iterating for 2D matrix // Outer loop for rows for (i = 1; i <= n; i++) { // Inner loop for columns for (j = 1; j <= i; j++) { // Printing value to be displayed System.out.print(k + " "); // Incremeting value displayed k++; } // Print elements of next row System.out.println(); } } } Output1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Time Complexity: O(n2) for given n Auxiliary Space: O(1) Java Program to Print Floyd's Triangle Comment A abhijithoyur Follow 7 Improve A abhijithoyur Follow 7 Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface4 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like