Inverted Pyramid number pattern in Java
- Home
- Number pattern
- Inverted Pyramid number pattern in Java
- On
- By
- 0 Comment
- Categories: Number pattern, 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
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
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
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
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 Python language
Nested for loop in C++ language
Nested for loop in Java language
Nested for loop in Python language