SlideShare a Scribd company logo
35 Star Pattern Programs In Java | Pattern Program
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:
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:
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:
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 ]
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:
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 ]
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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
## Print star pattern in java ##
*****
* *
* *
* *
*****
Pattern 32:
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
## Print triangle of stars in java ##
* *
* *
*
* *
* *
Pattern 33:
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:
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:
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

More Related Content

What's hot

Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
Fujio Kojima
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 
Java simple programs
Java simple programsJava simple programs
Java simple programsVEERA RAGAVAN
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
gersonjack
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
Intro C# Book
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
Ankit Gupta
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6fisher.w.y
 
Managing Mocks
Managing MocksManaging Mocks
Managing Mocks
Helen Sherwood-Taylor
 
WAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaWAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in java
One97 Communications Limited
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
Fariz Darari
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)
Fariz Darari
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
Mohammad Shaker
 
Code javascript
Code javascriptCode javascript
Code javascript
Ray Ray
 
Import java
Import javaImport java
Import java
heni2121
 
Data Structure
Data StructureData Structure
Data Structure
Hitesh Mohapatra
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabad
vasant Bhabad
 

What's hot (19)

R Debugging
R DebuggingR Debugging
R Debugging
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
 
Managing Mocks
Managing MocksManaging Mocks
Managing Mocks
 
WAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaWAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in java
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Code javascript
Code javascriptCode javascript
Code javascript
 
Import java
Import javaImport java
Import java
 
Data Structure
Data StructureData Structure
Data Structure
 
Lab 3
Lab 3Lab 3
Lab 3
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabad
 

Similar to Star pattern programs in java Print Star pattern in java and print triangle of stars in java, print star triangle of java, * pattern in java

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
KimVeeL
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
Ankit Gupta
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Aiman Hud
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
MLG College of Learning, Inc
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
anjanacottonmills
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
KimVeeL
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
angelsfashion1
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
jyotir7777
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
Katecate1
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
anupamfootwear
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
dorisc7
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
davinci54
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
Nithin Kumar,VVCE, Mysuru
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
One97 Communications Limited
 
Java final lab
Java final labJava final lab
Java final lab
Vivek Kumar Sinha
 

Similar to Star pattern programs in java Print Star pattern in java and print triangle of stars in java, print star triangle of java, * pattern in java (20)

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
Java file
Java fileJava file
Java file
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
 
Java final lab
Java final labJava final lab
Java final lab
 

Recently uploaded

What website can I sell pi coins securely.
What website can I sell pi coins securely.What website can I sell pi coins securely.
What website can I sell pi coins securely.
DOT TECH
 
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Vighnesh Shashtri
 
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
Falcon Invoice Discounting
 
一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理
一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理
一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理
ydubwyt
 
PF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptxPF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptx
GunjanSharma28848
 
Scope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theoriesScope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theories
nomankalyar153
 
how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.
DOT TECH
 
how to sell pi coins at high rate quickly.
how to sell pi coins at high rate quickly.how to sell pi coins at high rate quickly.
how to sell pi coins at high rate quickly.
DOT TECH
 
how can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYChow can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYC
DOT TECH
 
how to sell pi coins on Binance exchange
how to sell pi coins on Binance exchangehow to sell pi coins on Binance exchange
how to sell pi coins on Binance exchange
DOT TECH
 
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
beulahfernandes8
 
Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024
Commercial Bank of Ceylon PLC
 
how to sell pi coins effectively (from 50 - 100k pi)
how to sell pi coins effectively (from 50 - 100k  pi)how to sell pi coins effectively (from 50 - 100k  pi)
how to sell pi coins effectively (from 50 - 100k pi)
DOT TECH
 
Webinar Exploring DORA for Fintechs - Simont Braun
Webinar Exploring DORA for Fintechs - Simont BraunWebinar Exploring DORA for Fintechs - Simont Braun
Webinar Exploring DORA for Fintechs - Simont Braun
FinTech Belgium
 
Poonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit Card
Poonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit CardPoonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit Card
Poonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit Card
nickysharmasucks
 
Isios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdfIsios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdf
Henry Tapper
 
655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf
morearsh02
 
Introduction to Value Added Tax System.ppt
Introduction to Value Added Tax System.pptIntroduction to Value Added Tax System.ppt
Introduction to Value Added Tax System.ppt
VishnuVenugopal84
 
What price will pi network be listed on exchanges
What price will pi network be listed on exchangesWhat price will pi network be listed on exchanges
What price will pi network be listed on exchanges
DOT TECH
 
Financial Assets: Debit vs Equity Securities.pptx
Financial Assets: Debit vs Equity Securities.pptxFinancial Assets: Debit vs Equity Securities.pptx
Financial Assets: Debit vs Equity Securities.pptx
Writo-Finance
 

Recently uploaded (20)

What website can I sell pi coins securely.
What website can I sell pi coins securely.What website can I sell pi coins securely.
What website can I sell pi coins securely.
 
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
Empowering the Unbanked: The Vital Role of NBFCs in Promoting Financial Inclu...
 
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
innovative-invoice-discounting-platforms-in-india-empowering-retail-investors...
 
一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理
一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理
一比一原版BCU毕业证伯明翰城市大学毕业证成绩单如何办理
 
PF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptxPF-Wagner's Theory of Public Expenditure.pptx
PF-Wagner's Theory of Public Expenditure.pptx
 
Scope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theoriesScope Of Macroeconomics introduction and basic theories
Scope Of Macroeconomics introduction and basic theories
 
how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.how can i use my minded pi coins I need some funds.
how can i use my minded pi coins I need some funds.
 
how to sell pi coins at high rate quickly.
how to sell pi coins at high rate quickly.how to sell pi coins at high rate quickly.
how to sell pi coins at high rate quickly.
 
how can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYChow can I sell pi coins after successfully completing KYC
how can I sell pi coins after successfully completing KYC
 
how to sell pi coins on Binance exchange
how to sell pi coins on Binance exchangehow to sell pi coins on Binance exchange
how to sell pi coins on Binance exchange
 
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
Exploring Abhay Bhutada’s Views After Poonawalla Fincorp’s Collaboration With...
 
Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024Commercial Bank Economic Capsule - May 2024
Commercial Bank Economic Capsule - May 2024
 
how to sell pi coins effectively (from 50 - 100k pi)
how to sell pi coins effectively (from 50 - 100k  pi)how to sell pi coins effectively (from 50 - 100k  pi)
how to sell pi coins effectively (from 50 - 100k pi)
 
Webinar Exploring DORA for Fintechs - Simont Braun
Webinar Exploring DORA for Fintechs - Simont BraunWebinar Exploring DORA for Fintechs - Simont Braun
Webinar Exploring DORA for Fintechs - Simont Braun
 
Poonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit Card
Poonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit CardPoonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit Card
Poonawalla Fincorp and IndusInd Bank Introduce New Co-Branded Credit Card
 
Isios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdfIsios-2024-Professional-Independent-Trustee-Survey.pdf
Isios-2024-Professional-Independent-Trustee-Survey.pdf
 
655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf655264371-checkpoint-science-past-papers-april-2023.pdf
655264371-checkpoint-science-past-papers-april-2023.pdf
 
Introduction to Value Added Tax System.ppt
Introduction to Value Added Tax System.pptIntroduction to Value Added Tax System.ppt
Introduction to Value Added Tax System.ppt
 
What price will pi network be listed on exchanges
What price will pi network be listed on exchangesWhat price will pi network be listed on exchanges
What price will pi network be listed on exchanges
 
Financial Assets: Debit vs Equity Securities.pptx
Financial Assets: Debit vs Equity Securities.pptxFinancial Assets: Debit vs Equity Securities.pptx
Financial Assets: Debit vs Equity Securities.pptx
 

Star pattern programs in java Print Star pattern in java and print triangle of stars in java, print star triangle of java, * pattern in java

  • 1. 35 Star Pattern Programs In Java | Pattern Program 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 ##");
  • 2. // 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: import java.util.Scanner; public class Pattern2 {
  • 3. 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
  • 4. Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## * ** *** **** ***** Pattern 3: 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
  • 5. 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: import java.util.Scanner;
  • 6. 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(); }
  • 7. } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## ***** **** *** ** * Pattern 5: [ Pyramid Star Pattern ] 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++)
  • 8. { // 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:
  • 9. 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(" "); }
  • 10. } scanner.close(); } } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## ********* ******* ***** *** * Pattern 7: [Diamond Star Pattern ] 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 ");
  • 11. 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("*");
  • 12. } System.out.println(); } scanner.close(); } } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## * *** ***** ******* ********* ******* ***** *** * Pattern 8: import java.util.Scanner; public class Pattern8 { public static void main(String[] args)
  • 13. { // 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++)
  • 14. { 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: import java.util.Scanner;
  • 15. 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++) {
  • 16. // 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 ## * ** *** **** ***** **** *** ** *
  • 17. 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("*"); }
  • 18. System.out.println(); } scanner.close(); } } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## ***** ***** ***** ***** ***** Pattern 11: 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
  • 19. 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 ## ***** ***** *****
  • 20. ***** ***** Pattern 12: 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(); }
  • 21. 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:
  • 22. 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(); }
  • 23. 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 ## ***** **** *** ** * ** *** ****
  • 24. ***** Pattern 14: 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("* ");
  • 25. } 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 ## * * * * * * * * * * * * * * *
  • 26. * * * * * * * * * * * * * * Pattern 15: 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)
  • 27. 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: import java.util.Scanner; public class Pattern16 { public static void main(String[] args) {
  • 28. // 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(); } }
  • 29. Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## * ** * * * * ***** Pattern 17: 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 ##");
  • 30. 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 ## ***** * * * *
  • 31. ** * Pattern 18: 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
  • 32. 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: import java.util.Scanner; public class Pattern19
  • 33. { 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(); }
  • 34. scanner.close(); } } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## * * * * * * * ********* Pattern 20: 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 ");
  • 35. 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
  • 36. ## Printing the pattern ## ********* * * * * * * * Pattern 21: 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--)
  • 37. { 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(" "); }
  • 38. System.out.println(); } scanner.close(); } } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## * * * * * * * * * * * * * * * * Pattern 22: import java.util.Scanner; public class Pattern22 { public static void main(String[] args)
  • 39. { // 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)
  • 40. 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 ## * ** * * * * * * * * * * ** *
  • 41. Pattern 23: 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++) {
  • 42. 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
  • 43. Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## * ** * * * * * * * * * * ** * Pattern 24: 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();
  • 44. 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 ## ***** * * * *
  • 45. * * ***** Pattern 25: 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++)
  • 46. { 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: import java.util.Scanner; public class Pattern26 {
  • 47. 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(); }
  • 48. 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 ## * * ** ** *** *** **** ****
  • 49. ********** **** **** *** *** ** ** * * Pattern 27: 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++) {
  • 50. 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();
  • 51. } scanner.close(); } } Output Enter the number of rows needed to print the pattern 5 ## Printing the pattern ## ********** **** **** *** *** ** ** * * * * ** ** *** *** **** **** ********** Pattern 28: import java.util.Scanner; public class Pattern28 { public static void main(String[] args) {
  • 52. // 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(" ");
  • 53. } 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:
  • 54. 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
  • 55. 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 ## * * * * *
  • 56. * * * * * * * * * * * * * * * * * * Pattern 30: 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++)
  • 57. { 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: import java.util.Scanner; public class Pattern31 { public static void main(String[] args)
  • 58. { // 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
  • 59. ## Print star pattern in java ## ***** * * * * * * ***** Pattern 32: 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++)
  • 60. { 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 ## Print triangle of stars in java ## * * * * * * * * * Pattern 33: import java.util.Scanner;
  • 61. 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++) {
  • 62. 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: import java.util.Scanner;
  • 63. 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++)
  • 64. { 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:
  • 65. 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 {
  • 66. 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