Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern.
In the previous article, we have discussed Java Program to Print Inverted Right-Angled Triangle with Same Binary Number in Alternate Rows Pattern
In this article we will see how to print inverted right-angled triangle with decreasing order repeated number pattern.
- Java Code to Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern
- C Code to Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern
- C++ Code to Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern
Example-1 When size value=5 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
Example-2: When size value=4 4 4 4 4 3 3 3 2 2 1
Now, let’s see the actual program to print it.
Interested in programming and want to excel in it by choosing the short ways. Then, practicing with the available Java Program list is mandatory.
Approach:
- Enter total size and number store them in integer variables
size
. - Take one outer for loop to iterate the rows.
- Take inner for loop to iterate column means printing value for each row.
Java Code to Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern
import java.util.Scanner; class Main { public static void main(String[] args) { // taking size of no. of iteration //Row and column are the iterators int size , numberOfRows , numberOfColumns; // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows : "); size = scanner.nextInt(); //Outer loop to iterate the rows //Iterates from size to 1 for ( numberOfRows = size; numberOfRows >=1 ; numberOfRows--) { //Inner loop to iterate the columns //Iterates from 1 to row value for ( numberOfColumns = 1; numberOfColumns <= numberOfRows ; numberOfColumns++) System.out.print(numberOfRows); // printing in new line System.out.println(); } } }
Output : Enter the number of rows : 5 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
C Code to Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern
#include <stdio.h> #include <stdlib.h> int main() { int size , numberOfRows , numberOfColumns; printf("Enter the number of rows : "); scanf ("%d",&size); for ( numberOfRows = size; numberOfRows >=1 ; numberOfRows--) { for ( numberOfColumns = 1; numberOfColumns <= numberOfRows ; numberOfColumns++) printf("%d ",numberOfRows ); printf("\n"); } return 0; }
Output : Enter the number of rows : 5 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
C++ Code to Print Inverted Right-Angled Triangle with Decreasing Order Repeated Number Pattern
#include <bits/stdc++.h> using namespace std; int main() { int size , numberOfRows , numberOfColumns; printf("Enter the number of rows : "); scanf ("%d",&size); for ( numberOfRows = size; numberOfRows >=1 ; numberOfRows--) { for ( numberOfColumns = 1; numberOfColumns <=numberOfRows ; numberOfColumns++) cout << numberOfRows ; cout << "\n"; } return 0; }
Output : Enter the number of rows : 5 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.
Related Java Number Pattern Programs:
- Java Program to Print Inverted Right-Angled Triangle with Increasing Order Repeated Number Pattern.
- Java Program to Print Inverted Right-Angled Triangle with Increasing Number Pattern.
- Java Program to Print Inverted Right-Angled Triangle with Decreasing Number Pattern
- Java Program to Print Exponentially Increasing Number Pattern