Thursday, 23 June 2016

Program to print a Star Pattern Type-7.

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

Code:

import java.util.Scanner;
public class StarPattern7
{
    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;
        for (i=0; i<line; i++)
        {
            for (j=0; j<line; j++)
            {
                System.out.printf(" * ");
            }
            System.out.printf("\n");
        }
    }
}

Program to print a Star Pattern Type-6.

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

Code:

import java.util.Scanner;
public class StarPattern6
{
    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;
        for (i=0; i<line; i++)
        {
            for (j=0; j<=i; j++)
            {
                System.out.printf(" * ");
            }
            System.out.printf("\n");
        }
    }
}

Program to print a Star Pattern Type-5.

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

Code:

import java.util.Scanner;
public class StarPattern5
{
    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=1; i<=line; i++)
       {
            for (j=line; j>=i; j--)
           {
                System.out.printf(" ");
            }
            for (k=1; k<=i; k++)
           {
                System.out.printf("*");
            }
            System.out.printf("\n");
        }
    }
}
 

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");
        }
    }
 }

Program to print a Star Pattern Type-3.

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

Code:

import java.util.Scanner;
public class StarPattern3
{
    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;
        for (i=line; i>=1; i--)
        {
            for (j=1; j<=i; j++)
            {
                System.out.printf(" * ");
            }
            System.out.printf("\n");
        }
    }
 }

Program to print a Star Pattern Type-2.

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

Code:

import java.util.Scanner;
public class StarPattern2
{
    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;
        for (i=1; i<=line; i++)
        {
            for (k=t; k<line; k++)
            {
                System.out.printf(" ");
            }
            for (j=0; j< i; j++)
            {
                System.out.printf(" * ");
                t = t + 1;
            }
            System.out.printf("\n");
        }
    }
 }

Program to print a Star Pattern Type-1.

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

Code:

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