Are You Feeling any difficulity while writing Core-Java Programs. Send those to me Here.

Series Programs-2

Program: 5
public class HelloWorld{
     public static void main(String []args){
        for(int i=0;i<10;i++){
            for(int k=10;k>i;k--)
            System.out.print(" ");
            for(int j=0;j<i;j++){
                System.out.print("*");
            }
            System.out.println("");
        }
     }
}



Output:
                                *
                            *  *
                        *  *  *
                    *  *  *  *
                *  *  *  *  *
            *  *  *  *  *  *
        *  *  *  *  *  *  *
    *  *  *  *  *  *  *  *
*  *  *  *  *  *  *  *  *

Program: 6
public class HelloWorld{
     public static void main(String []args){
        for(int i=1;i<20;i+=2){
            for(int k=20;k>i;k-=2)
            System.out.print(" ");
            for(int j=0;j<i;j++){
                System.out.print("*");
            }
            System.out.println("");
        }
     }
}

Output:
          *
        * * *
        * * * * *
      * * * * * * *
      * * * * * * * * *
    * * * * * * * * * * *
* * * * * * * * * * * * *
  * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *



No comments:

Post a Comment