
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Print Mirror Upper Star Triangle Pattern
In this article, we will understand how to print mirror upper star triangle pattern. The pattern is formed by using multiple for-loops and print statements.
Below is a demonstration of the same −
Input
Suppose our input is −
Enter the number of rows : 8
Output
The desired output would be −
The mirror upper star pattern : ******** ******* ****** ***** **** *** ** *
Algorithm
Step 1 - START Step 2 - Declare four integer values namely i, j, k and my_input Step 3 - Read the required values from the user/ define the values Step 4 - We iterate through two nested 'for' loops inside a ‘for’ loop to get space between the characters. Step 5 - After iterating through the innermost loop, we iterate through another 'for' loop. This will help print the required character. Step 6 - Now, print a newline to get the specific number of characters in the subsequent lines. Step 7 - Display the result Step 8 - Stop
Example 1
Here, the input is being entered by the user based on a prompt. You can try this example live in our coding ground tool .
import java.util.Scanner; public class MirrorTriangle{ public static void main(String args[]){ int i, j, k, my_input; System.out.println("Required packages have been imported"); Scanner my_scanner = new Scanner(System.in); System.out.println("A reader object has been defined "); System.out.print("Enter the number of rows : "); my_input = my_scanner.nextInt(); System.out.println("The mirror upper star pattern: "); for (i= my_input; i>= 1; i--){ for (j=my_input; j>i;j--){ System.out.print(" "); } for (k=1;k<=i;k++){ System.out.print("*"); } System.out.println(""); } } }
Output
Required packages have been imported A reader object has been defined Enter the number of rows : 8 The mirror upper star pattern: ******** ******* ****** ***** **** *** ** *
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class MirrorTriangle{ public static void main(String args[]){ int i, j, k, my_input; my_input = 8; System.out.println("The number of rows is defined as " +my_input); System.out.println("The mirror upper star pattern: "); for (i= my_input; i>= 1; i--){ for (j=my_input; j>i;j--){ System.out.print(" "); } for (k=1;k<=i;k++){ System.out.print("*"); } System.out.println(""); } } }
Output
The number of rows is defined as 8 The mirror upper star pattern: ******** ******* ****** ***** **** *** ** *
- Related Articles
- Swift Program to Print Mirror Upper Star Triangle Pattern
- Golang Program To Print Mirror Upper Star Triangle Pattern
- C++ Program to Print Mirror Upper Star Triangle Pattern
- Java Program to Print Upper Star Triangle Pattern
- Java Program to Print Mirror Lower Star Triangle Pattern
- Swift program to Print Upper Star Triangle Pattern
- Golang Program To Print Upper Star Triangle Pattern
- C++ Program to Print Upper Star Triangle Pattern
- Swift program to Print Mirror Lower Star Triangle Pattern
- Golang Program To Print Mirror Lower Star Triangle Pattern
- Java Program to Print Downward Triangle Star Pattern
- Java Program to Print Left Triangle Star Pattern
- Java Program to Print Hollow Right Triangle Star Pattern
- Java Program to Print the Left Triangle Star Pattern
- Swift program to Print Upper Numeric Triangle Pattern

Advertisements