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
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
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
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
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
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…