Thursday, 23 June 2016

Program to print a Star Pattern Type-4.

Explanation :
If n=6 then output will be
  ******
    *****
      ****
        ***
          **
            *.

Code:

import java.util.Scanner;
public class StarPattern4
{
    public static void main( String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the no. of lines: ");
        int line=sc.nextInt();
     
        int i,j,k,t=0,samp=1;
        for (i=line; i>=1; i--)
        {
            for (k=samp; k>=0; k--)
            {
                System.out.printf(" ");
               
            }
            for (j=i; j>=1; j--)
            {
                System.out.printf("*");
            }
            samp = samp + 1;
            System.out.printf("\n");
        }
    }
 }

No comments:

Post a Comment