Pattern Programs:

1) Printing pattern
5 4 3 2 1 
5 4 3 2 
5 4 3 
5 4 
5 

public class Pattern1 {

	void add(){
       for(int row=1;row<=5;row++) {
    	   for(int col=5;col>=row;col--) {
    		   System.out.print(col+" ");
    	   }
    	   System.out.println();
       }
	}
}
public static void main(String[] args) {
Pattern2 p1=new Pattern1();
p1.add();
}
}

3)Printing pattern
1 1 1 1 1 
2 2 2 2 
3 3 3 
4 4 
5 
Program :
public class Pattern3 {
        void add()
   for(int row=1;row<=5;row++) {
	   for(int col=5;col>=row;col--) {
		   System.out.print(row+" ");
	   }
	   System.out.println();
   }
	}
}

public static void main(String[] args) {
Pattern3 p3=new Pattern3();
p3.add();

}

4) Printing pattern
5 5 5 5 5 
4 4 4 4 
3 3 3 
2 2 
1 


class Pattern4{
	 void add(){
		for(int row=5;row>=1;row--) {
			for(int col=1;col<=row;col++) {
				System.out.print(row+" ");
			}
			System.out.println();
		}
	}
}
public static void main(String[] args) {
Pattern4 p4=new Pattern4();
p4.add();
}
}

5)Printing pattern
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 

class Pattern5
{	
void add(){
		for(int row=1;row<=5;row++) {
			for(int col=1;col<=row;col++) {
				System.out.print(col+" ");
			}
			System.out.println();
		}
	}
}
public static void main(String[] args) {
Pattern5 p5=new Pattern5();
p5.add();
}
}

6) Printing pattern  
5 
5 4 
5 4 3 
5 4 3 2 
5 4 3 2 1 

Program 
public class Pattern6 {

	void add(){
  for(int row=5;row>=1;row--) {
	  for(int col=5;col>=row;col--) {
		  System.out.print(col+" ");
	  }
	  System.out.println();
  }
	}

}
public static void main(String[] args) {
Pattern5 p5=new Pattern5();
p5.add();
}
}

7)Print pattern
5 
4 4 
3 3 3 
2 2 2 2 
1 1 1 1 1 

public class Pattern7{
	void add(){
  for(int row=5;row>=1;row--) {
	  for(int col=5;col>=row;col--) {
		  System.out.print(row+" ");
	  }
	  System.out.println();
  }
	}
}
public static void main(String[] args) {
Pattern7 p7=new Pattern7();
p7.add();
}
}

Leave a comment

Design a site like this with WordPress.com
Get started