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

Hiraniahmad 237 views 66 slides Oct 19, 2019
Slide 1
Slide 1 of 66
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66

About This Presentation

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


Slide Content

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