Wednesday 7 December 2016

Pattern Star in java

CODE: 

import java.util.*;
class Star3
{
    public static void main(String[] args)
    {
        int i,j,k,l,num;
        Scanner sc= new Scanner(System.in);
        System.out.print("Enter the Height : ");
        num= sc.nextInt();
       
        for (i=1;i<=num;i++)
        {
            for (j=num;j>=i;j--)
            {
                System.out.print(" *");
            }
       
            for(k=0;k<(i*2-1)-2;k++)
            {
            System.out.print("  ");
            }
           
            for(l=num;l>=i;l--)
            {
                if(i==1 && l==1)
                {
                    continue;
                }
                System.out.print(" *");
            }
            System.out.print("\n");
        }
       
    }
}

OUTPUT:
Enter the Height :2

* * * * *
* *    * *
*           *

No comments:

Post a Comment