Java Program to Print Upper Star Triangle Pattern Last Updated : 11 Oct, 2022 Comments Improve Suggest changes Like Article Like Report The upper star triangle pattern means the base has to be at the bottom and there will only be one star to be printed in the first row. Here is the issue that will arise is what way we traverse be it forward or backward we can't ignore the white spaces, so we are not able to print a star in the first row using only two nested for loops. The answer to this is very simple as we will break this problem into two halves, we will be running two nested for loops, one managing white spaces and the other managing pattern printing rest remains the same. Example Java // Java Program to Print Upper Star Triangle Pattern // Main class public class GFG { // Main driver method public static void main(String[] args) { // Declaring and initializing variable representing // number of rows to be printed int k = 9; // Nested 2 for loops for iterating over the matrix // Outer for loop for iterating over rows for (int a = 0; a <= k; a++) { // Inner for loop for iterating over columns // where we are printing white spaces for (int b = 1; b <= k - a; b++) { // Print the white space System.out.print(" "); } // Inner for loop for iterating over columns // where we are printing white spaces for (int l = 0; l <= a; l++) { // Print the star pattern System.out.print("*"); } // By now we are done with one row so // next line System.out.println(""); } } } Output * ** *** **** ***** ****** ******* ******** ********* ********** Time Complexity: O(n2), where n represents the given input.Auxiliary Space: O(1), no extra space is required, so it is a constant. Comment More infoAdvertise with us D ddeevviissaavviittaa Follow Improve Article Tags : Java Java Programs java-basics Practice Tags : Java Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 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 Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 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 Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like