Software Development Exam  >  Software Development Notes  >  Basics of Java  >  Code: Star Patterns

Code: Star Patterns | Basics of Java - Software Development PDF Download

Code: Star Patterns | Basics of Java - Software Development

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

Code: Star Patterns | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development

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 | Basics of Java - Software Development is a part of the Software Development Course Basics of Java.
All you need of Software Development at this link: Software Development
60 videos|37 docs|12 tests

Up next

60 videos|37 docs|12 tests
Download as PDF

Up next

Explore Courses for Software Development exam
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

shortcuts and tricks

,

Objective type Questions

,

Sample Paper

,

Code: Star Patterns | Basics of Java - Software Development

,

Code: Star Patterns | Basics of Java - Software Development

,

video lectures

,

pdf

,

Summary

,

Extra Questions

,

Exam

,

Semester Notes

,

MCQs

,

ppt

,

practice quizzes

,

mock tests for examination

,

Previous Year Questions with Solutions

,

Important questions

,

Free

,

Viva Questions

,

study material

,

Code: Star Patterns | Basics of Java - Software Development

,

past year papers

;