Tuesday, 1 October 2019

Different Number Pattern Programs In Java

Different Number Pattern Programs In Java

package basiccode.allstring.examples; public class Patterns { public static void main(String args[]){ /* 1 1 1 2 1 2 1 2 3 1 2 3 1 2 3 4 1 2 3 4 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 */ */ int rows=7; for(int i=1;i<=rows;i++){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } /* 1 1 1 2 1 2 1 2 3 1 2 3 1 2 3 4 1 2 3 4 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 4 1 2 3 1 2 3 1 2 1 2 1 1 */ */ for(int i=1;i<=rows;i++){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } //Printing lower half of the pattern //Printing lower half of the pattern for(int i=rows-1;i>=1;i--){ for(int i=rows-1;i>=1;i--){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } /* * * * * 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 */ for(int i=1;i<=rows;i++){ for(int i=1;i<=rows;i++){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(i+" "); System.out.print(i+" "); } } System.out.println(); System.out.println(); } } /* /* 7 6 5 4 3 2 1 7 6 5 4 3 2 1 7 6 5 4 3 2 7 6 5 4 3 2 7 6 5 4 3 7 6 5 4 3 7 6 5 4 7 6 5 4 7 6 5 7 6 5 7 6 7 6 7 7 */ */ for(int i=1;i<=rows;i++){ for(int j=rows;j>=i;j--){ for(int j=rows;j>=i;j--){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } /* * * 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 4 1 2 3 1 2 3 1 2 1 2 1 1 * * */ */ rows=7; rows=7; for(int i=rows;i>=1;i--){ for(int i=rows;i>=1;i--){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } /* * * 7 6 5 4 3 2 1 7 6 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 4 3 2 1 4 3 2 1 3 2 1 3 2 1 2 1 2 1 1 1 */ */ for(int i=rows;i>=1;i--){ for(int j=i;j>=1;j--){ for(int j=i;j>=1;j--){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } /* /* * * * * 7 7 7 6 7 6 7 6 5 7 6 5 7 6 5 4 7 6 5 4 7 6 5 4 3 7 6 5 4 3 7 6 5 4 3 2 7 6 5 4 3 2 7 6 5 4 3 2 1 7 6 5 4 3 2 1 */ */ System.out.println("**************************"); System.out.println("**************************"); for(int i=rows;i>=1;i--){ for(int i=rows;i>=1;i--){ for(int j=rows;j>=i;j--){ for(int j=rows;j>=i;j--){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } System.out.println("**************************"); /* /* 1 1 1 2 1 1 2 1 1 2 3 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 5 4 3 2 1 1 2 3 4 5 6 5 4 3 2 1 1 2 3 4 5 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 7 6 5 4 3 2 1 */ for(int i=1;i<=rows;i++){ for(int i=1;i<=rows;i++){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } for(int j=i-1;j>=1;j--){ for(int j=i-1;j>=1;j--){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } /* * * Pattern programs in java : Pattern 9 Pattern programs in java : Pattern 9 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 4 1 2 3 1 2 3 1 2 1 2 1 1 1 2 1 2 1 2 3 1 2 3 1 2 3 4 1 2 3 4 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 */ */ System.out.println("**************************"); System.out.println("**************************"); for(int i=rows;i>=1;i--){ for(int i=rows;i>=1;i--){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } //Printing lower half of the pattern //Printing lower half of the pattern for(int i=2;i<=rows;i++){ for(int i=2;i<=rows;i++){ for(int j=1;j<=i;j++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } System.out.println("##########################################"); System.out.println("##########################################"); //Pattern programs in java : Pattern 10 //Pattern programs in java : Pattern 10 System.out.println("Pattern programs in java "); System.out.println("Pattern programs in java "); /* /* 1234567 1234567 234567 234567 34567 34567 4567 4567 567 567 67 67 7 7 67 67 567 567 4567 4567 34567 34567 234567 234567 1234567 1234567 */ */ int count=rows; int count=rows; for(int i=1;i<rows;i++){ for(int i=1;i<rows;i++){ //Printing i spaces at the beginning of each row //Printing i spaces at the beginning of each row for (int j = 1; j < i; j++) for (int j = 1; j < i; j++) { { System.out.print(" "); System.out.print(" "); } } //Printing i to rows value at the end of each row //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) for (int j = i; j <= rows; j++) { { System.out.print(j); System.out.print(j); } } System.out.println(); System.out.println(); } } //Printing lower half of the pattern for (int i = rows-1; i >= 1; i--) { { //Printing i spaces at the beginning of each row //Printing i spaces at the beginning of each row for (int j = 1; j < i; j++) for (int j = 1; j < i; j++) { { System.out.print(" "); System.out.print(" "); } } //Printing i to rows value at the end of each row //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) for (int j = i; j <= rows; j++) { { System.out.print(j); System.out.print(j); } } System.out.println(); System.out.println(); } } System.out.println("##################################3"); System.out.println("##################################3"); //Pattern programs in java : Pattern 11 /* /* 1 1 2 1 2 1 3 2 1 3 2 1 4 3 2 1 4 3 2 1 5 4 3 2 1 5 4 3 2 1 6 5 4 3 2 1 6 5 4 3 2 1 7 6 5 4 3 2 1 7 6 5 4 3 2 1 */ for(int i=1;i<=rows;i++){ for(int i=1;i<=rows;i++){ for(int j=i;j>=1;j--){ for(int j=i;j>=1;j--){ System.out.print(j); System.out.print(j); } } System.out.println(); System.out.println(); } } /* * * Pattern programs in java : Pattern 12 Pattern programs in java : Pattern 12 1 10 10 101 101 1010 1010 10101 10101 101010 101010 1010101 1010101 * * */ */ for (int i = 1; i <= rows; i++) for (int i = 1; i <= rows; i++) { { for (int j = 1; j <= i; j++){ for (int j = 1; j <= i; j++){ if(j%2 == 0) if(j%2 == 0) { { System.out.print(0); System.out.print(0); } } else else { { System.out.print(1); System.out.print(1); } } } } System.out.println(); System.out.println(); } } System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"); /* /* * * Pattern programs in java : Pattern 13 Pattern programs in java : Pattern 13 1 2 3 4 5 6 7 1 2 3 4 5 6 7 2 3 4 5 6 7 2 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 4 5 6 7 4 5 6 7 5 6 7 5 6 7 6 7 6 7 7 7 6 7 6 7 5 6 7 5 6 7 4 5 6 7 4 5 6 7 3 4 5 6 7 3 4 5 6 7 2 3 4 5 6 7 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 * * */ */ for(int i=1;i<=rows;i++){ //Printing i spaces at the beginning of each row //Printing i spaces at the beginning of each row for(int j=1;j<i;j++){ for(int j=1;j<i;j++){ System.out.print(""); System.out.print(""); } } //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) for (int j = i; j <= rows; j++) { { System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } for (int i = rows-1; i >= 1; i--) { { //Printing i spaces at the beginning of each row //Printing i spaces at the beginning of each row for (int j = 1; j < i; j++) for (int j = 1; j < i; j++) { { System.out.print(" "); System.out.print(" "); } } //Printing i to rows value at the end of each row //Printing i to rows value at the end of each row for (int j = i; j <= rows; j++) for (int j = i; j <= rows; j++) { { System.out.print(j+" "); System.out.print(j+" "); } } System.out.println(); System.out.println(); } } } } }

No comments:

Post a Comment

Note: only a member of this blog may post a comment.