• Java
    • JAXB Tutorial
      • What is JAXB
      • JAXB Marshalling Example
      • JAXB UnMarshalling Example
  • Spring Tutorial
    • Spring Core Tutorial
    • Spring MVC Tutorial
      • Quick Start
        • Flow Diagram
        • Hello World Example
        • Form Handling Example
      • Handler Mapping
        • BeanNameUrlHandlerMapping
        • ControllerClassNameHandlerMapping
        • SimpleUrlHandlerMapping
      • Validation & Exception Handling
        • Validation+Annotations
        • Validation+ResourceBundle
        • @ExceptionHandler
        • @ControllerAdvice
        • Custom Exception Handling
      • Form Tag Library
        • Textbox Example
        • TextArea Example
        • Password Example
        • Dropdown Box Example
        • Checkboxes Example
        • Radiobuttons Example
        • HiddenValue Example
      • Misc
        • Change Config file name
    • Spring Boot Tutorial
  • Hibernate Tutorial
  • REST Tutorial
    • JAX-RS REST @PathParam Example
    • JAX-RS REST @QueryParam Example
    • JAX-RS REST @DefaultValue Example
    • JAX-RS REST @Context Example
    • JAX-RS REST @MatrixParam Example
    • JAX-RS REST @FormParam Example
    • JAX-RS REST @Produces Example
    • JAX-RS REST @Consumes Example
    • JAX-RS REST @Produces both XML and JSON Example
    • JAX-RS REST @Consumes both XML and JSON Example
  • Miscellaneous
    • JSON Parser
      • Read a JSON file
      • Write JSON object to File
      • Read / Write JSON using GSON
      • Java Object to JSON using JAXB
    • CSV Parser
      • Read / Write CSV file
      • Read/Parse/Write CSV File – OpenCSV
      • Export data into a CSV File
      • CsvToBean and BeanToCsv – OpenCSV

JavaInterviewPoint

Java Development Tutorials

35 Star Pattern Programs In Java | Pattern Program

March 18, 2019 by javainterviewpoint 21 Comments

In this article, we will learn to print the different Star Pattern Programs in Java. This is one of the popular Java pattern program interview question for fresher. The pattern program are the most recommended programs to enhance the logical thinking and for the better understanding of flow control. Lets look into the below possible Star Pattern Programs in Java which might help for both the fr

Star Pattern Programs In Java

Star Pattern Programs In Java 1

Star Pattern Programs In Java 3

Star Pattern Programs In Java

Pattern 1:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern1
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j=1; j<=i; j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*
**
***
****
*****

Pattern 2:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern2
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++) 
        { 
            // Print space in decreasing order 
            for (int j=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k=1; k<=i; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   **
  ***
 ****
*****

Pattern 3:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern3
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++) 
        { 
            // Print star in decreasing order 
            for (int k=rows; k>=i; k--)
            {
                System.out.print("*");
            }
            // Print space in increasing order
            for (int j=1; j<i; j++)
            {
                System.out.print(" ");
            }
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
**** 
***  
**   
*

Pattern 4:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern4
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in increasing order
            for (int j=1; j<i; j++) 
            { 
                System.out.print(" "); 
            } 
            // Print star in decreasing order 
            for (int k=rows; k>=i; k--)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
 ****
  ***
   **
    *

Pattern 5: [ Pyramid Star Pattern ]

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern5
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++) 
        { 
            // Print space in decreasing order 
            for (int j=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k=1; k<=(i * 2) -1; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   ***
  *****
 *******
*********

Pattern 6:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern6
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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=rows; i>=1; i--)
        {
            // Print star in decreasing order
            for (int k=1; k<=(i * 2) -1; k++) 
            { 
                System.out.print("*"); 
            } 
            System.out.println(); 
            // Print space in increasing order 
            for (int j=rows; j>=i; j--)
            {
                System.out.print(" ");
            }
            
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*********
 *******
  *****
   ***
    *

Pattern 7: [Diamond Star Pattern ]

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern7
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++) 
        { 
            // Print space in decreasing order 
            for (int j=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k=1; k<=(i * 2) -1; k++) 
            { 
               System.out.print("*"); 
            } 
            System.out.println(); 
        } 
        for (int i=rows-1; i>=1; i--)
        {
         // Print space in increasing order
            for (int j=rows-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k=1; k<=(i * 2) -1; k++)
            {
                System.out.print("*");
            }
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

Pattern 8:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern8
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        
        for (int i=1; i<=rows-1; i++) 
        { 
            // Print star in decreasing order 
            for (int j = rows-1; j >= i; j--)
            {
                System.out.print("*");
            }
            // Print space in increasing order
            for (int k = 1; k < i; k++)
            {
                System.out.print(" ");
            }
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*
**
***
****
*****
****
*** 
**  
*

Pattern 9:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern9
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in decreasing order
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k = 1; k <= i; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i = 1; i <= rows-1; i++)
        {
            // Print space in increasing order
            for (int j = 1; j <= i; j++)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k = rows-1; k >= i; k--)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   **
  ***
 ****
*****
 ****
  ***
   **
    *

Pattern 10:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern10
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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 = rows-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k = 1; k <= rows; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *****
   *****
  *****
 *****
*****

Pattern 11:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern11
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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-1; j++)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k = 1; k <= rows; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
 *****
  *****
   *****
    *****

Pattern 12:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern12
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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 = rows; i >= 1; i--)
        {
            for (int j = i; j >= 1; j--)
            {
                System.out.print("*");
            }
            System.out.println();
        }

        for (int i = 2; i <= rows; i++)
        {
            for (int j = i; j >= 1; j--)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
****
***
**
*
**
***
****
*****

Pattern 13:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern13
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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; k <= rows; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i = rows-1; i >= 1; i--)
        {
            for (int j = 2; j <=i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
 ****
  ***
   **
    *
   **
  ***
 ****
*****

Pattern 14:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern14
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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; k <= rows; k++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }
        for (int i = rows-1; i >= 1; i--)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print("* ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
* * * * * 
 * * * * 
  * * * 
   * * 
    * 
   * * 
  * * * 
 * * * * 
* * * * *

Pattern 15:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern15
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j=1; j<=i; j++)
            {
                if( j == 1 || j == i || i == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*
**
* *
*  *
*****

Pattern 16:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern16
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in decreasing order
            for (int j=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k=1; k<=i; k++)
            {
                if( k == 1 || k == i || i == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   **
  * *
 *  *
*****

Pattern 17:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern17
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print star in decreasing order
            for (int j=rows; j >=i; j--)
            {
                if( i == 1 || j == i || j == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            // Print space in increasing order
            for (int k=1; k<i; k++)
            {
                System.out.print(" ");
            }
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
*  * 
* *  
**   
*

Pattern 18:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern18
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in increasing order
            for (int j=1; j<i; j++)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k=rows; k>=i; k--)
            {
                if( i == 1 || k == i || k == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
 *  *
  * *
   **
    *

Pattern 19:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern19
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in decreasing order
            for (int j=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k=1; k<=(i * 2) -1; k++)
            {
                if( k == 1 || k == (i * 2) -1 || i == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   * *
  *   *
 *     *
*********

Pattern 20:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern20
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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=rows; i>=1; i--)
        {
            // Print star in decreasing order
            for (int j=1; j <=(i * 2) -1; j++)
            {
                if( j == 1 || j == (i * 2) -1 || i == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
            // Print space in increasing order
            for (int k = rows; k >= i; k--)
            {
                System.out.print(" ");
            }
            
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*********
 *     *
  *   *
   * *
    *

Pattern 21:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern21
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in decreasing order
            for (int j=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k=1; k<=(i * 2) -1; k++)
            {
                if( k == 1 || k == (i * 2) -1)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        for (int i=rows-1; i>=1; i--)
        {
         // Print space in increasing order
            for (int j=rows-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k=1; k<=(i * 2) -1; k++)
            {
                if( k == 1 || k == (i * 2) -1 )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    *

Pattern 22:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern22
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j=1; j<=i; j++)
            {
                if( j == 1 || j == i )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        
        for (int i=1; i<=rows-1; i++)
        {
            // Print star in decreasing order
            for (int j = rows-1; j >= i; j--)
            {
                if( j == rows-1 || j == i || i == rows)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            // Print space in increasing order
            for (int k = 1; k < i; k++)
            {
                System.out.print(" ");
            }
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*
**
* *
*  *
*   *
*  *
* * 
**  
*

Pattern 23:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern23
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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++)
        {
            // Print space in decreasing order
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }
            // Print star in increasing order
            for (int k = 1; k <= i; k++)
            {
                if( k == 1 || k == i )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        for (int i = 1; i <= rows-1; i++)
        {
            // Print space in increasing order
            for (int j = 1; j <= i; j++)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k = rows-1; k >= i; k--)
            {
                if( k == rows-1 || k == i )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   **
  * *
 *  *
*   *
 *  *
  * *
   **
    *

Pattern 24:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern24
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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 = rows-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k = 1; k <= rows; k++)
            {
                if( i == 1 || i == rows || k == 1 || k == rows  )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *****
   *   *
  *   *
 *   *
*****

Pattern 25:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern25
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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-1; j++)
            {
                System.out.print(" ");
            }
            // Print star in decreasing order
            for (int k = 1; k <= rows; k++)
            {
                if( i == 1 || i == rows || k == 1 || k == rows  )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
 *   *
  *   *
   *   *
    *****

Pattern 26:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern26
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        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();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*        *
**      **
***    ***
****  ****
**********
****  ****
***    ***
**      **
*        *

Pattern 27:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern27
{
    public static void main(String[] args)
    {
     // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j = i; j <= rows; j++)
            {
                System.out.print("*");
            }
            for (int k = 1; k <= i*2-2; k++)
            {
                System.out.print(" ");
            }
            for (int l = i; l <= rows; l++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print("*");
            }
            for (int k = i*2-2; k < rows*2-2; k++)
            {
                System.out.print(" ");
            }
            for (int l = 1; l <= i; l++)
            {
                System.out.print("*");
            }
            
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
**********
****  ****
***    ***
**      **
*        *
*        *
**      **
***    ***
****  ****
**********

Pattern 28:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern28
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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=rows; j>i; j--)
            {
                System.out.print(" ");
            }
            for (int k=1; k<=(i * 2) -1; k++)
            {
                if(k == 1 || k == i*2 -1 || k == 1)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        for (int i=rows-1; i>=1; i--)
        {
            for (int j=rows-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            for (int k=1; k<=(i * 2) -1; k++)
            {
                if(k == 1 || k == i*2 -1 || k == 1)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }

            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    *

Pattern 29:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern29
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        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; k <= rows; k++)
            {
                if( i == 1 || k == i || k == rows)
                    System.out.print("* ");
                else
                    System.out.print("  ");
            }
            System.out.println();
        }
        for (int i = rows-1; i >= 1; i--)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                if( i == 1 || k == i || k == rows)
                    System.out.print("* ");
                else
                    System.out.print("  ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
* * * * * 
 *     * 
  *   * 
   * * 
    * 
   * * 
  *   * 
 *     * 
* * * * *

Pattern 30:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern30
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j=1; j<=rows; j++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
*****
*****
*****
*****

Pattern 31:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern31
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

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

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=rows; i++)
        {
            for (int j=1; j<=rows; j++)
            {
                if(i ==1 || i == rows   || j == 1 || j == rows )
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to print the pattern 
5
## Printing the pattern ##
*****
*   *
*   *
*   *
*****

Pattern 32:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern32
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows needed to in the pattern ");

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=(rows * 2 -1); i++)
        {
            for (int j=1; j<=rows; j++)
            {
                if(j==i || j==rows-i+1)
                {
                    System.out.print("*");
                }
                System.out.print(" ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to in the pattern 
5
## Printing the pattern ##
*    * 
 *  *  
  *   
 *  *  
*    *

Pattern 33:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern33
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows needed to in the pattern ");

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");
        
        // Print i number of stars
        for (int i=1; i<=(rows * 2 -1); i++)
        {
            if( i == rows)
            {
                // Printing Horizontal Line of Stars
                for (int j=1; j<=(rows * 2 -1); j++)
                {
                    System.out.print("*");
                }
            }
            else
            {
                // Printing space before Vertical Line of Stars
                for(int k=1; k<= rows-1; k++)
                {
                    System.out.print(" ");
                }
                System.out.print("*");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to in the pattern 
5
## Printing the pattern ##
    *
    *
    *
    *
*********
    *
    *
    *
    *

Pattern 34:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern34
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows needed to in the pattern ");

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");

        // Print i number of stars
        for (int i = 1; i <= rows * 2 - 1; i++)
        {
            if (i == 1 || i == rows || i == rows * 2 - 1)
            {
                for (int j = 1; j <= rows; j++)
                {
                    if (j == 1 || j == rows)
                        System.out.print(" ");
                    else
                        System.out.print("*");
                }
            }
            else
            {
                for (int k = 1; k <= rows; k++)
                {
                    if (k == 1 || k == rows)
                        System.out.print("*");
                    else
                        System.out.print(" ");
                }
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows needed to in the pattern 
5
## Printing the pattern ##
 *** 
*   *
*   *
*   *
 *** 
*   *
*   *
*   *
 ***

Pattern 35:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern35
{
    public static void main(String[] args)
    {
    	// Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows needed to in the pattern ");

        int rows = scanner.nextInt();
        System.out.println("## Printing the pattern ##");

        // Print i number of stars
        
        for(int i=1; i<= rows; i++)
        {
            if(i%2 != 0)
            {
                for(int j=1; j<= rows/2+1; j++)
                {
                    System.out.print("*  ");
                }
            }
            else
            {
            	for(int j=1; j<= rows/2; j++)
                {
                    System.out.print(" * ");
                }
            }
            System.out.println("");
        }
    }
}

Output

Enter the number of rows needed to in the pattern 
5
## Printing the pattern ##
*  *  *  
 *  * 
*  *  *  
 *  * 
*  *  *

Filed Under: Java, Java Interview Tagged With: Diamond pattern, Half Diamond Pattern, Hollow Triangle Pattern, Inverted Pyramid, Java Star Pattern Program, Pyramid pattern, Right Triangle Pattern, Star Pattern Program Star Pattern, Triangle Pattern

Comments

  1. Raj says

    April 26, 2019 at 9:01 pm

    **
    *
    ****(4*)
    *
    ********(8*)
    *
    ****************(16*)

    Code for this

    Reply
    • javainterviewpoint says

      April 27, 2019 at 1:38 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              int counter = 1;
              for(int i=1; i<= 7; i++)
              {
                  if(i%2 != 0)
                  {
                      for(int j=1; j<= Math.pow(2, counter); j++)
                      {
                          System.out.print("* ");
                      }
                      counter++;
                  }
                  else
                  {
                      System.out.print("*");
                  }
                  System.out.println("");
              }
          }
      }
      Reply
  2. Parikshit Naskar says

    June 5, 2019 at 9:42 am

    I have star problem. Please solve the problem
    -*-*-*-*
    –*-*-*-
    -*-*-*-*
    –*-*-*-
    -*-*-*-*
    –*-*-*-

    Reply
    • javainterviewpoint says

      June 5, 2019 at 8:30 pm

      Here you go

      public static void main(String[] args)
          {
              for(int i=1; i<= 7; i++)
              {
                  if(i%2 != 0)
                  {
                      for(int j=1; j<= 4; j++)
                      {
                          System.out.print("_*");
                      }
                  }
                  else
                  {
                  	System.out.print("_");
                  	for(int j=1; j<= 3; j++)
                      {
                          System.out.print("_*");
                      }
                  	System.out.print("_");
                  }
                  System.out.println("");
              }
          }
      Reply
    • sunil says

      August 8, 2020 at 8:47 pm

      *#######
      ######**
      ***#####
      ####****
      ****####
      #####***
      **######
      #######*

      Reply
      • javainterviewpoint says

        August 9, 2020 at 11:17 am

        Here you go

        package com.javainterviewpoint;
        
        public class Pattern {
          public static void main(String[] args) {
            int rows = 8;
        
            for (int i = 1; i <= rows / 2; i++) {
              for (int j = 1; j <= rows; j++) {
                if (i % 2 == 0) {
                  if (j <= (rows - i)) {
                    System.out.print("#");
                  } else {
                    System.out.print("*");
                  }
                } else {
                  if (j <= i) {
                    System.out.print("*");
                  } else {
                    System.out.print("#");
                  }
                }
              }
              System.out.println();
            }
            for (int i = rows / 2; i >= 1; i--) {
              for (int j = 1; j <= rows; j++) {
                if (i % 2 == 0) {
                  if (j <= i) {
                    System.out.print("*");
                  } else {
                    System.out.print("#");
                  }
                } else {
                  if (j <= (rows - i)) {
                    System.out.print("#");
                  } else {
                    System.out.print("*");
                  }
                }
              }
              System.out.println();
            }
          }
        }
        Reply
  3. carol denvers says

    June 14, 2019 at 2:28 pm

    * * * * *
    * * * *
    * *
    * * * *
    * * * * *

    Reply
    • javainterviewpoint says

      June 15, 2019 at 1:40 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              int rows = 3;
              int space =2;
              
              //Upper Half
              
              for(int i= 1; i<=rows; i++)
              {
                  // Five Spaces
                  for(int m=1; m<=5; m++)
                  {
                      System.out.print(" ");
                  }
                  //Left Triangle
                  for(int j=rows; j>=i; j--)
                  {
                      System.out.print("* ");
                  }
                  
                  // Space in the middle
                  if(i!=1)
                  {
                      for(int l=1; l<=space; l++)
                      {
                          System.out.print(" ");
                      }
                      space = space + 4;
                  }
                  
                  //Right Triangle
                  if(i==1)
                  {
                      for(int k=rows-1; k>=i; k--)
                      {
                          System.out.print("* ");
                      }
                  }
                  else
                  {
                      for(int k=rows; k>=i; k--)
                      {
                          System.out.print("* ");
                      }
                  }
                  System.out.println();
              }
              
              //Lower Half
              
              space = space - 4;
              for(int i= 2; i<=rows; i++)
              {
                  // Five Spaces
                  for(int m=1; m<=5; m++)
                  {
                      System.out.print(" ");
                  }
                  
                  //Left Triangle
                  for(int j=1; j<=i; j++)
                  {
                      System.out.print("* ");
                  }
                  
                  // Space in the middle
                  space = space - 4;
                  for(int l=space; l>=1; l--)
                  {
                      System.out.print(" ");
                  }
      
                  //Right Triangle
                  if(i==rows)
                  {
                      for(int k=1; k<=i-1; k++)
                      {
                          System.out.print("* ");
                      }
                  }
                  else
                  {
                      for(int k=1; k<=i; k++)
                      {
                          System.out.print("* ");
                      }
                  }
                  System.out.println();
              }
          }
      }
      Reply
  4. Aaaaaa says

    August 22, 2019 at 12:21 am

    Give me answers to this star output
    _ _ _ _ *
    _ _ _***
    _ _*****
    _*******
    *********
    *********
    *********
    *********
    *********

    Reply
    • javainterviewpoint says

      August 23, 2019 at 12:07 pm

      Here you go

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		for(int i=1; i<=5; i++)
      		{
      			for(int j=5-i; j >= 1; j--)
      			{
      				System.out.print("_ ");
      			}
      			for(int k=i*2-1; k>=1; k--)
      			{
      				System.out.print("*");
      			}
      			System.out.println();
      		}
      		for(int i=1; i<5; i++)
      		{
      			for(int l=5*2-1; l>=1; l--)
      			{
      				System.out.print("*");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  5. irteza khan says

    August 30, 2019 at 8:18 pm

    i have a star problem as follows with some lines printed in between. solve this
    *_*_*_*_*_*_*_*
    *_*_*_*_*_*_*
    *_*_*_*_*_*
    *_*_*_*_*
    *_*_*_*
    *_*_*
    *_*
    *
    welcome to java
    welcome to computer science
    programming is fun
    *_*_*_*_*_*_*_*
    *_*_*_*_*_*_*
    *_*_*_*_*_*
    *_*_*_*_*
    *_*_*_*
    *_*_*
    *_*
    *

    Reply
    • javainterviewpoint says

      September 2, 2019 at 12:43 pm

      Here you go
      Pattern1

      public class Pattern
      {
          public static void main(String[] args)
          {
              for(int i=1; i<=8; i++)
              {
                  for (int k=2; k<=i; k++)
                  {
                      System.out.print("    ");
                  }
                  for(int j=1; j<=8-i+1; j++)
                  {
                      if(j == 1)
                          System.out.print("*");
                      else
                          System.out.print("_*");
                  }
                  
                  System.out.println();
              }
          }
      }

      Pattern2

      public class Pattern
      {
          public static void main(String[] args)
          {
              for(int i=1; i<=8; i++)
              {
                  for(int j=1; j<=8-i+1; j++)
                  {
                      if(j == 1)
                          System.out.print("*");
                      else
                          System.out.print("_*");
                  }
                  System.out.println();
              }
          }
      }
      Reply
  6. Puneet says

    October 21, 2019 at 9:24 pm

    I have a pattern problem can you solve this:
    1.Condition: N=1
    Output: *
    2.Condition: N=5
    Output: *####
    ###**
    ***##
    ###**
    *####

    Reply
    • javainterviewpoint says

      October 24, 2019 at 7:15 pm

      Here you go

      public class Test
      {
      	public static void main(String[] args)
      	{
      		int n = 3;
      		if (n == 1)
      			System.out.println("*");
      		else
      		{
      			int rows = 1;
      			for (int i = 1; i <= n / 2 + 1; i++)
      			{
      				if (rows % 2 == 0)
      				{
      					for (int k = n - i; k >= 1; k--)
      					{
      						System.out.print("#");
      					}
      					for (int j = 1; j <= i; j++)
      					{
      						System.out.print("*");
      					}
      					rows++;
      
      				} else
      				{
      					for (int j = 1; j <= i; j++)
      					{
      						System.out.print("*");
      					}
      					for (int k = n - i; k >= 1; k--)
      					{
      						System.out.print("#");
      					}
      					rows++;
      				}
      				System.out.println();
      			}
      			
      			for (int i = 1; i <= n / 2; i++)
      			{
      				if (rows % 2 == 0)
      				{
      					for (int k = n / 2 + i; k >= 1; k--)
      					{
      						System.out.print("#");
      					}
      					for (int j = n / 2; j >=i; j--)
      					{
      						System.out.print("*");
      					}
      					rows++;
      				} else
      				{
      					for (int j = n / 2; j >=i; j--)
      					{
      						System.out.print("*");
      					}
      					for (int k = n / 2 + i; k >= 1; k--)
      					{
      						System.out.print("#");
      					}
      					rows++;
      				}
      
      				System.out.println();
      			}
      		}
      	}
      }
      Reply
  7. Shibananda says

    April 19, 2020 at 3:30 pm

    Java is very interesting

    Reply
  8. Aayushrathi says

    August 21, 2020 at 4:45 pm

    It was very helpful. Please give a program for this too.
    *
    #*
    *#*
    #*#*
    *#*#*

    Reply
    • javainterviewpoint says

      August 21, 2020 at 9:26 pm

      Here you go

      public class Pattern {
          public static void main(String[] args) {
              int temp;
              for (int i = 1; i <= 5; i++) {
                  temp = i;
                  for (int j = 1; j <= i; j++) {
                      if (temp % 2 != 0) {
                          System.out.print("* ");
                      } else {
                          System.out.print("# ");
                      }
                      temp++;
                  }
                  System.out.println();
              }
          }
      }
      Reply
  9. tushar gupta says

    September 19, 2020 at 4:11 pm

    **********
    **** ****
    *** ***
    ** **
    * *
    Make this methoud java program please

    Reply
    • javainterviewpoint says

      September 21, 2020 at 1:55 pm

      Here you go

      public class Pattern {
      	public static void main(String[] args) {
      		int rows = 5;
      		for (int i = 1; i <= rows; i++) {
      			for (int j = rows; j >= i; j--) {
      				System.out.print("*");
      			}
      			for (int k = 1; k <= (i * 2) - 1; k++) {
      				if (i == 1)
      					System.out.print("*");
      				else
      					System.out.print(" ");
      			}
      			for (int l = rows; l >= i; l--) {
      				System.out.print("*");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  10. xristos says

    November 23, 2020 at 9:54 pm

    can u make this pattern in java?
    given n=3 for example:
    **1
    *23
    456
    or given n=4
    ***1
    **23
    *456
    78910

    Reply
    • javainterviewpoint says

      December 4, 2020 at 1:03 pm

      Here you go, apologies for the delayed response

      public class Pattern {
      	public static void main(String[] args) {
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      		int rows = scanner.nextInt();
      		int temp = 1;
      		System.out.println("** Printing the pattern... **");
      		for (int i = 1; i <= rows; i++) {
      
      			for (int j = rows; j > i; j--) {
      				System.out.print("* ");
      			}
      
      			for (int k = 1; k <= i; k++) {
      				System.out.print(temp + " ");
      				temp++;
      			}
      
      			System.out.println();
      		}
      	}
      }
      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Java Basics

  • JVM Architecture
  • Object in Java
  • Class in Java
  • How to Set Classpath for Java in Windows
  • Components of JDK
  • Decompiling a class file
  • Use of Class.forName in java
  • Use Class.forName in SQL JDBC

Oops Concepts

  • Inheritance in Java
  • Types of Inheritance in Java
  • Single Inheritance in Java
  • Multiple Inheritance in Java
  • Multilevel Inheritance in Java
  • Hierarchical Inheritance in Java
  • Hybrid Inheritance in Java
  • Polymorphism in Java – Method Overloading and Overriding
  • Types of Polymorphism in java
  • Method Overriding in Java
  • Can we Overload static methods in Java
  • Can we Override static methods in Java
  • Java Constructor Overloading
  • Java Method Overloading Example
  • Encapsulation in Java with Example
  • Constructor in Java
  • Constructor in an Interface?
  • Parameterized Constructor in Java
  • Constructor Chaining with example
  • What is the use of a Private Constructors in Java
  • Interface in Java
  • What is Marker Interface
  • Abstract Class in Java

Java Keywords

  • Java this keyword
  • Java super keyword
  • Final Keyword in Java
  • static Keyword in Java
  • Static Import
  • Transient Keyword

Miscellaneous

  • newInstance() method
  • How does Hashmap works internally in Java
  • Java Ternary operator
  • How System.out.println() really work?
  • Autoboxing and Unboxing Examples
  • Serialization and Deserialization in Java with Example
  • Generate SerialVersionUID in Java
  • How to make a class Immutable in Java
  • Differences betwen HashMap and Hashtable
  • Difference between Enumeration and Iterator ?
  • Difference between fail-fast and fail-safe Iterator
  • Difference Between Interface and Abstract Class in Java
  • Difference between equals() and ==
  • Sort Objects in a ArrayList using Java Comparable Interface
  • Sort Objects in a ArrayList using Java Comparator

Follow

  • Coding Utils

Useful Links

  • Spring 4.1.x Documentation
  • Spring 3.2.x Documentation
  • Spring 2.5.x Documentation
  • Java 6 API
  • Java 7 API
  • Java 8 API
  • Java EE 5 Tutorial
  • Java EE 6 Tutorial
  • Java EE 7 Tutorial
  • Maven Repository
  • Hibernate ORM

About JavaInterviewPoint

javainterviewpoint.com is a tech blog dedicated to all Java/J2EE developers and Web Developers. We publish useful tutorials on Java, J2EE and all latest frameworks.

All examples and tutorials posted here are very well tested in our development environment.

Connect with us on Facebook | Privacy Policy | Sitemap

Copyright ©2023 · Java Interview Point - All Rights Are Reserved ·