Java Program For Printing 180 Degree Rotation of Simple Half Left Pyramid Last Updated : 22 Sep, 2023 Comments Improve Suggest changes Like Article Like Report We can utilize 'for' and 'while' loops to print a 180-degree rotation of a simple half-left pyramid in Java as follows: Example of 180-degree Rotation of Simple Half-Left PyramidRows = 5Output : * * * * * * * * * * * * * * * Methods For Printing 180-Degree Rotation of Simple Half-Left PyramidThere are certain methods to Print the 180-rotated Simple Half-Left Pyramid mentioned below: Using a 'for' loopUsing a 'while' loop1. Using a 'for' loopIn this approach two for loops are utilized where, the first for loop identifies the number of rows while the second for loop identifies a number of columns. Here the values will be altered according to the first for loop. If j is greater than i then it will print the output otherwise it will print the space. Below is the implementation of the above method: Java //Java program for above approach public class PyramidRotation { public static void main(String[] args) { int rows = 5; // The outer loop is used to identify the number of rows. for (int i = 0; i < rows; i++) { // The inner loop is used to print spaces before the asterisks. for (int j = 0; j < rows - i - 1; j++) { System.out.print(" "); } // The second inner loop is used to print asterisks. for (int k = 0; k <= i; k++) { System.out.print("* "); } System.out.println(); // Move to the next line after each row. } } } Output * * * * * * * * * * * * * * * 2. Using a 'while' loopExplanation: The while loop checks for the condition until the condition becomes false. If the condition is true then it enters into the loop and executes the statements Below is the implementation of the above method: Java //Java Program for above approach public class PyramidRotation { public static void main(String[] args) { int i = 0, j = 0, sp = 0; int rows = 5; // The outer while loop continues until the condition (i < rows) is false. while (i < rows) { // The inner while loop is used to print spaces before the asterisks. while (sp < (rows - i - 1)) { System.out.print(" "); // Printing two spaces. sp++; } // Reset sp to 0 for the next row. sp = 0; // This loop prints the asterisks and spaces pattern. while (j <= i) { System.out.print("* "); // Printing an asterisk followed by a space. j++; } // Reset j to 0 for the next row. j = 0; i++; System.out.println(); // Move to the next line after each row. } } } Output * * * * * * * * * * * * * * * Complexity of the above methodTime complexity: O(n2) for given input of 'n' rowsAuxiliary space: O(1) Comment More infoAdvertise with us Next Article Java Program For Printing 180 Degree Rotation of Simple Half Left Pyramid O ojash29oct Follow Improve Article Tags : Java Java Programs Geeks Premier League pattern-printing Java-Pattern Geeks Premier League 2023 +2 More Practice Tags : Javapattern-printing Similar Reads Java Program for Rotate a Matrix by 180 degree Given a square matrix, the task is that we turn it by 180 degrees in an anti-clockwise direction without using any extra space. Examples : Input : 1 2 3 4 5 6 7 8 9 Output : 9 8 7 6 5 4 3 2 1 Input : 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 Output : 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 Method: 1 (Only prints ro 6 min read Programs for printing pyramid patterns in Java This article is aimed at giving a Java implementation for pattern printing. Simple pyramid pattern Java import java.io.*; // Java code to demonstrate star patterns public class GeeksForGeeks { // Function to demonstrate printing pattern public static void printStars(int n) { int i, j; // outer loop 11 min read Java Program to Print Pyramid Star Pattern This article will guide you through the process of printing a Pyramid star pattern in Java. 1. Simple pyramid pattern Java import java.io.*; // Java code to demonstrate Pyramid star patterns public class GeeksForGeeks { // Function to demonstrate printing pattern public static void PyramidStar(int n 5 min read Java Program to Print array after it is right rotated K times Given an Array of size N and a values K, around which we need to right rotate the array. How to quickly print the right rotated array?Examples :  Input: Array[] = {1, 3, 5, 7, 9}, K = 2. Output: 7 9 1 3 5 Explanation: After 1st rotation - {9, 1, 3, 5, 7} After 2nd rotation - {7, 9, 1, 3, 5} Input: 2 min read Java Program to Print Reverse Pyramid Star Pattern Approach: 1. Get the number of input rows from the user using Scanner Class or BufferedReader Class object. 2. Now run two loops Outer loop to iterate through a number of rows as initialized or input is taken from reader class object in java. Now,Run an inner loop from 1 to 'i-1'Ru another inner loo 4 min read Like