0% found this document useful (0 votes)
35 views

Patterns

Uploaded by

bishaljaiswal515
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Patterns

Uploaded by

bishaljaiswal515
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1)

* * * * *
* *
* *
* * * * *

public class for_looo_patterns {


public static void main(String [] args){
int row = 4;
int colmn = 5;
for(int i = 1; i <=row; i++){
for(int j = 1; j<=colmn; j++){
if(i==1 || i == row || j==1 || j==colmn){
System.out.print("* ");
}else{
System.out.print(" ");
}}
System.out.println(); } }}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

2)

*
* *
* * *
* * * *
* * * * *

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
int colmn = 5;
for(int i = 1; i<=row; i++){
for(int j = 1; j<=colmn; j++){
if(i+j >= 6){
System.out.print("* ");
}else{
System.out.print(" ");}}
System.out.println();} }}
3)

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
int colmn = 5;
for(int i = 1; i<=row; i++){
for(int j = 1; j<=colmn; j++){
if(i+j >= 7){
System.out.print(" ");
}else{
System.out.print(j+ " ");}}
System.out.println();} }}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

4)

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
int a = 1;
for(int i = 1; i<=row; i++){
for(int j = 1; j<=i; j++){
System.out.print(a+ " ");
a++;
}
System.out.println();
} }}
5)
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
int colmn = 5;
for(int i = 1; i<=row; i++){
for(int j = 1; j<=i; j++){
if((i+j)%2==0){
System.out.print("1 ");
}else{
System.out.print("0 ");}}
System.out.println();} }}

6)
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
public class for_loop_patterns{
public static void main(String [] args){
int row = 4;
int colmn = 8;
for(int i = 1; i<= row; i++){
for(int j = 1; j<= colmn; j++){
if(i < j && j<= colmn -i ){
System.out.print(" ");
}else{
System.out.print("* ");}}
System.out.println();}

for(int i = row; i>= 1; i--){


for(int j = colmn; j>= 1; j--){
if(i < j && j<= colmn -i ){
System.out.print(" ");
}else{
System.out.print("* ");}}
System.out.println();} }}
7)

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
for(int i = 1; i<=row; i++){
for(int j = 1; j <=(row-i); j++){
System.out.print(" ");}
for(int j = 1; j <= row; j++){
System.out.print("* ");
}
System.out.println();} }}

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

8)
* * * * *
* *
* *
* *
* * * * *

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
int colmn = 5;
for(int i = 1; i<= row; i++){
for(int j =1; j<=row-i; j++){
System.out.print(" ");}
for(int j = 1; j<= row; j++){
if(i ==1 || i==row || j==1 || j == colmn ){
System.out.print("* ");
} else {
System.out.print(" ");
}
}
System.out.println();} }}
9)
*
* * *
* * * * *
* * * * * * *
* * * * * * *
* * * * *
* * *
*

public class for_loop_patterns{


public static void main(String [] args){
int row = 4;
for(int i = 1; i <= row; i++){
for(int j= 1; j<= row-i; j++){
System.out.print(" ");}
for(int j = 1; j <= 2*i -1; j++){
System.out.print("* ");}
System.out.println();}

for(int i = row; i >= 1; i--){


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

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

10)
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

public class for_loop_patterns{


public static void main(String [] args){
int row = 5;
for(int i = 1; i<= row; i++){
for(int j = 1; j<=(row -i); j++){
System.out.print(" ");}
for(int j = 1; j <= i;j++){
System.out.print(i+" ");
System.out.print(" ");}
System.out.println();} }}
11)

1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5

public class for_loop_patterns {

public static void main(String [] args){


int row = 5;
for(int i = 1; i<= row; i++){
for(int j = 1; j<= (row-i); j++){
System.out.print(" ");}
for(int j = i; j>=1; j--){
System.out.print(j+" ");}
for( int j=2; j>=2 && j<=i;j++){
System.out.print(j+ " ");}
System.out.println();}
}}

You might also like