EmSAT Achieve Exam  >  EmSAT Achieve Notes  >  Java for EmSAT Achieve  >  Code: Star Patterns

Code: Star Patterns | Java for EmSAT Achieve PDF Download

Code: Star Patterns | Java for EmSAT Achieve

1. Write a python program to print following star pattern: 

Code: Star Patterns | Java for EmSAT Achieve

public class IncreasingTriangle

{

   public static void main (String args[])

   {

      int n = 5;

      for (int i = 1; i<=n ; i++) 

      {

         for (int j = 1; j<=n; j++) {

           System.out.print("* ");

         }

         System.out.println();

      }

   }

}

2. Write a python program to print following pattern: 

Code: Star Patterns | Java for EmSAT Achieve

public class IncreasingTriangle

{

   public static void main (String args[])

   {

      int n = 5;

      for (int i = 1; i<=n ; i++) 

      {

         for (int j = 1; j<=i; j++) {

            System.out.print("* ");

         }

         System.out.println();

      }

   }

}

3. Write a python code to print following star pattern: 

Code: Star Patterns | Java for EmSAT Achieve

public class DecreasingTriangle

{

   public static void main (String args[])

   {

      int n = 5;

      for (int i = 1; i<=n ; i++) {

         for (int j = i; j<=n; j++) {

            System.out.print(“* ”);

         }

         System.out.println();

     }

  }

}

4. Write a python code to print following pattern: 

Code: Star Patterns | Java for EmSAT Achieve

import java.util.Scanner; 

public class RightStarTriangle 

{

     public static void main(String args[])

     {

          Scanner sc = new Scanner(System.in);

          System.out.println("Enter the number of rows:");

          int n= sc.nextInt();

          for (int i = 1; i<=n ; i++) {

             for (int j = i; j<=n; j++) {

             System.out.print(" ");

          }

          for (int j = 1; j<=i; j++) {

             System.out.print("* ");

          }

          System.out.println();

       }

    }

 }

5. Write a python program to print following star pattern: 

Code: Star Patterns | Java for EmSAT Achieve

public class RightStarTriangle

{

     public static void main(String args[])

     {

          int n= 5;

          for (int i = 1; i<=n ; i++) {

             for (int j = 1; j<=i; j++) {

               System.out.print(“ ”);

             }

             for (int j = i; j<=n; j++) {

               System.out.print(“* ”);

             }

             System.out.println();

           }

        }

  }

6. Write a python program to print following hill star pattern: 

Code: Star Patterns | Java for EmSAT Achieve

import java.util.Scanner;

public class StarPyramid 

{

    public static void main(String args[])

    {

        Scanner scan = new Scanner(System.in);

       System.out.print("Enter Number of Rows : ");

       int n = scan.nextInt();


       for (int i = 1; i<=n ; i++) { 

          for (int j = i; j<=n; j++) {

             System.out.print(" ");

          }

          for (int j = 1; j< i; j++) { 

             System.out.print("* ");

          }

          for (int j = 1; j<=i; j++) {

             System.out.print("* ");

          }

          System.out.println();

       }


     }

 }

7. Write a python program to print revers hill star pattern: 

Code: Star Patterns | Java for EmSAT Achieve

public class StarRe Hill

{

    public static void main(String args[])

    {

        int n = 5;

        for (int i = 1; i<=n ; i++) { 

          for (int j = 1; j<=i; j++) { // increasing

             System.out.print(“ ”);

          }

          for (int j = i; j< n; j++) { // decreasing

             System.out.print(“* ”);

          }

          for (int j = i; j<=n; j++) { // decreasing

             System.out.print(“* ”);

          }

          System.out.println();

       }

    }

}

8. Write a python code to print Dimond pattern with star: 

Code: Star Patterns | Java for EmSAT Achieve

import java.util.Scanner;

public class StarPyramid 

{

    public static void main(String args[])

    {

        Scanner scan = new Scanner(System.in);

        System.out.print("Enter Number of Rows : ");

        int n = scan.nextInt();

        for (int i = 1; i<=n;i++){

          for (int j = i; j<=n; j++) {

             System.out.print(" "); // decreasing

          }

          for (int j = 1; j< i; j++) { // increasing

             System.out.print("* ");

          }

          for (int j = 1; j<=i; j++) { // increasing

             System.out.print("* ");

          }

          System.out.println();

       }

       for (int i = 1; i<=n ; i++) {


          for (int j = 1; j<=i; j++) { // increasing

             System.out.print(" ");

          }

          for (int j = i; j< n; j++) { // decreasing

             System.out.print("* ");

          }

          for (int j = i; j<=n; j++) { // decreasing

             System.out.print("* ");

          }

          System.out.println();

       } 

}

}

9. Write a python code to print Butterfly pattern with star:

 Code: Star Patterns | Java for EmSAT Achieve

import java.util.Scanner;

public class StarPattern4

{

  public static void main(String[] args)

    {

        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter the number of rows needed to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println(" Printing the pattern ");

       

        for (int i=1; i<=rows; i++)

        {

            for (int j = 1; j <= i; j++)

            {

                System.out.print("*");

            }

            for (int k = i*2; k <= rows*2-1; k++)

            {

                System.out.print(" ");

            }

            for (int l = 1; l <= i; l++)

            {

                System.out.print("*");

            }

            System.out.println();

        }

       

        for (int i=1; i<=rows-1; i++)         {             for (int j = rows-1; j >= i; j--)

            {

                System.out.print("*");

            }

            for (int k = 1; k <= i*2; k++)             {                 System.out.print(" ");             }             for (int l = rows-1; l >= i; l--)

            {

                System.out.print("*");

            }

           

            System.out.println();

        }

        scanner.close();

    }

}

The document Code: Star Patterns | Java for EmSAT Achieve is a part of the EmSAT Achieve Course Java for EmSAT Achieve.
All you need of EmSAT Achieve at this link: EmSAT Achieve
60 videos|37 docs|12 tests

Top Courses for EmSAT Achieve

60 videos|37 docs|12 tests
Download as PDF
Explore Courses for EmSAT Achieve exam

Top Courses for EmSAT Achieve

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Important questions

,

Exam

,

video lectures

,

pdf

,

Viva Questions

,

study material

,

MCQs

,

Sample Paper

,

Code: Star Patterns | Java for EmSAT Achieve

,

past year papers

,

shortcuts and tricks

,

Code: Star Patterns | Java for EmSAT Achieve

,

Free

,

Summary

,

Previous Year Questions with Solutions

,

ppt

,

Code: Star Patterns | Java for EmSAT Achieve

,

Objective type Questions

,

practice quizzes

,

Semester Notes

,

Extra Questions

,

mock tests for examination

;