Monday, 7 March 2016

Star Pattern Program in java

* Pattern program 1:

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

}

OUTPUT:
*****
*****
*****
*****


* Pattern program 2:

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

}

OUTPUT:
*
**
***
****


* Pattern program 3:

public class star3 {
       public static void main(String args[]){
       for(int i=0;i<5;i++){
              if(i==0||i==4){
                     for(int j=0;j<5;j++){
                           System.out.print("*");
                     }System.out.println();
                     }else{
                           for(int k=0;k<5;k++){
                                  if(k==0||k==4){
                                        
                                         System.out.print("*");
                                         }
                                  else{
                                  System.out.print(" ");
                                  }
                           }
                           System.out.println();
                          
                     }
              }
       }
}
      
OUTPUT:
*****
*   *
*   *
*   *
*****              


* Pattern program 4:

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



       }

}

OUTPUT:
    *
   **
  ***
 ****
*****     


* Pattern program 5

public class star5 {
       public static void main(String args[]){
              System.out.println("The Pattern is");
              for(int i=1;i<=5;i++)
              {
                     for(int j=i;j<=5;j++)

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

                     {
                           System.out.print("+");
                     }
                     System.out.println();
              }
       }
}

OUTPUT:
*****
****
***
**
*
+
++
+++
++++
+++++   


* Pattern program 6

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

OUTPUT:
*****
****
***
**
*


* Pattern program 7

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

              for(int i=0;i<5;i++){
                     for(int j=i;j<5;j++){
                           System.out.print("*");
                     }
                     System.out.println();
              }
       }
}

OUTPUT:
*
**
***
****
*****
*****
****
***
**
*



You may also like to read to about:



2 comments:

  1. how to print pascal triangle ?

    ReplyDelete
    Replies
    1. Hi Reader,
      Please find the link to printing Pascal triangle in java given below:
      https://javaradar.blogspot.com/2017/10/pascal-triangle-in-java.html
      You can also find the link at the end of this post.

      Delete

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If you are looking for a reference book on java then we recommend you to go for → Java The Complete Reference
Click on the image link below to get it now.