Pattern 1:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
Java Program :
import java.util.Scanner; public class Pattern{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println( "How many rows you want in this pattern?" ); int rows = sc.nextInt(); System.out.println( "Here is your pattern....!!!" ); for ( int i = 1 ; i <= rows; i++) { for ( int j = 1 ; j <= i; j++) { System.out.print(i+ " " ); } System.out.println(); } //Close the resources sc.close(); } } |
Output :
How many rows you want in this pattern?
7
Here is your pattern….!!!
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
7
Here is your pattern….!!!
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
Pattern 2:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Java Program :
import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println( "How many rows you want in this pattern?" ); int rows = sc.nextInt(); System.out.println( "Here is your pattern....!!!" ); //Printing upper half of the pattern for ( int i = 1 ; i <= rows; i++) { for ( int j = 1 ; j <= i; j++) { System.out.print(j+ " " ); } System.out.println(); } //Printing lower half of the pattern for ( int i = rows- 1 ; i >= 1 ; i--) { for ( int j = 1 ; j <= i; j++) { System.out.print(j+ " " ); } System.out.println(); } //Closing the resources sc.close(); } } |
Output :
How many rows you want in this pattern?
7
Here is your pattern….!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
7
Here is your pattern….!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Pattern 3 :
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Java Program :
import java.util.Scanner; public class Pattern1{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println( "How many rows you want in this pattern?" ); int rows = sc.nextInt(); System.out.println( "Here is your pattern....!!!" ); for ( int i = rows; i >= 1 ; i--) { for ( int j = 1 ; j <= i; j++) { System.out.print(j+ " " ); } System.out.println(); } //Closing the resources sc.close(); } } |
Output :
How many rows you want in this pattern?
7
Here is your pattern….!!!
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
7
Here is your pattern….!!!
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Pattern 4 :
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
Java Program :
import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println( "How many rows you want in this pattern?" ); int rows = sc.nextInt(); System.out.println( "Here is your pattern....!!!" ); for ( int i = 1 ; i <= rows; i++) { for ( int j = rows; j >= i; j--) { System.out.print(j+ " " ); } System.out.println(); } //Closing the resources sc.close(); } } |
Output :
How many rows you want in this pattern?
7
Here is your pattern….!!!
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
7
Here is your pattern….!!!
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
Pattern 5 :
7
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1
Java Program :
import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println( "How many rows you want in this pattern?" ); int rows = sc.nextInt(); System.out.println( "Here is your pattern....!!!" ); for ( int i = rows; i >= 1 ; i--) { for ( int j = rows; j >= i; j--) { System.out.print(j+ " " ); } System.out.println(); } //Closing the resources sc.close(); } } |
Output :
How many rows you want in this pattern?
7
Here is your pattern….!!!
7
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1
7
Here is your pattern….!!!
7
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1
No comments:
Post a Comment