pyramid triangle

Inverted Pyramid number pattern in Java

Inverted Pyramid number pattern in Java

In tis tutorial, we will discuss about Inverted Pyramid number pattern in Java

Here we are vgoing to learn about how to create Inverted Pyramid number pattern in Java

Code to inverted Pyramid  pattern 1

Inverted number Piramid 1

Program

import java.util.Scanner; 
public class Pyramid_pattern4{
public static void main(String args[]){
Scanner sc=new Scanner(System.in); //Scanner class in java
System.out.print("Enter the rows you want");
int rows=sc.nextInt();
System.out.println("");

for (int i=1; i<=rows; i++){
  for (int j=1; j<=rows; j++){
  System.out.print(" ");
  }
 rows--;
for (int k=1; k<=i; k++){
  System.out.print(i+" ");           
}                                
System.out.println();
}
                                                   
}


}

 

1 2 3 4 5 6 7 8 9
   1 2 3 4 5 6 7 
      1 2 3 4 5 
         1 2 3
            1

 

 

Code to inverted Pyramid  pattern 2

Inverted Pyramid 2

Program

import java.util.Scanner; 
public class Invert_pattern2{
public static void main(String args[]){
Scanner sc=new Scanner(System.in); //Scanner class in java
System.out.print("Enter the rows you want");
int rows=sc.nextInt();
System.out.println("");

for (int i=rows; i>=1; i--){
  for (int j=0; j<=rows-i; j++){
  System.out.print(" ");
  }//print space
 int count=0;
while(count != (2*i-1)){
  System.out.print(i+"");  
count++;  
}                                
System.out.println();
}
                                                   
}
}

 

99999999999999999
  888888888888888
    7777777777777
      66666666666
        555555555
          4444444
            33333
              222
                1

 

Code to inverted Pyramid  pattern 3

Inverted Pyramid pattern 3

Program

import java.util.Scanner; 
public class Invert_pattern3{
public static void main(String args[]){
Scanner sc=new Scanner(System.in); //Scanner class in java
System.out.print("Enter the rows you want: ");
//Taking input(rows value) from user
int rows=sc.nextInt();
System.out.println("");
int count=rows;//initializing count with rows
for (int i=0; i<=rows; i++){
  for (int j=1; j<=i*2; j++){
  System.out.print(" ");
  }//print space at the bigining of each row
 
for(int j=1; j<=count; j++) {
System.out.print(j+" ");//print left part of pyramid
}
for(int j=count-1; j>=1; j--) {
System.out.print(j+" "); //print right part of pyramid
}
  System.out.println();   
count--;  
          }
      }
}

 

1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
   1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
      1 2 3 4 5 6 7 6 5 4 3 2 1
         1 2 3 4 5 6 5 4 3 2 1
            1 2 3 4 5 4 3 2 1
               1 2 3 4 3 2 1
                  1 2 3 2 1
                     1 2 1
                        1

 

Code to inverted Pyramid  pattern 4

Inverted Pyramid pattern – 4

Program

import java.util.Scanner;
public class Reverse_Pyramid{
public static void main(String args[]){
int rows;
Scanner s=new Scanner(System.in);
System.out.println("Enter number of rows");
rows=s.nextInt();
for(int i=1; i<=rows; i++){//do for rows in pyramid
   for(int j=1; j<=i; j++){
     System.out.print(" ");//print space

}
for(int k=i; k<=rows; k++){
     System.out.print(k+" ");

}
System.out.println();
}

}

}

 

1 2 3 4 5 6 7 8
 2 3 4 5 6 7 8
  3 4 5 6 7 8
   4 5 6 7 8
    5 6 7 8
     6 7 8
      7 8
       8

 

Suggested for you

For loop in C++ language

For loop in Java language

For loop in C language

For loop in Python language

 

Nested for loop in C++ language

Nested for loop in Java language

Nested for  loop in C language

Nested for loop in Python language

 

 

 

Floyd's triangle number pattern Using nested while loop in Java
CPP program to print Floyd's triangle number patterns
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago