SlideShare a Scribd company logo
35 Star PatternProgramsIn Java | PatternProgram
In thisarticle,we will learntoprintthe differentStarPatternProgramsinJava.Thisis one of the popular
Java patternprograminterviewquestionforfresher.The patternprogramare the mostrecommended
programsto enhance the logical thinkingandforthe betterunderstandingof flow control.Letslookinto
the belowpossibleStarPatternProgramsinJavawhichmighthelpforboth the fr
Star PatternProgramsIn Java
Star PatternProgramsIn Java 1
Star PatternProgramsIn Java 3
Star PatternProgramsIn Java
Pattern1:
package com.javainterviewpoint;
importjava.util.Scanner;
publicclassPattern1
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj=1; j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
***
****
*****
Pattern2:
importjava.util.Scanner;
publicclassPattern2
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace indecreasingorder
for(intj=rows;j>i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk=1; k<=i; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprint the pattern
5
## Printingthe pattern##
*
**
***
****
*****
Pattern3:
importjava.util.Scanner;
publicclassPattern3
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printstar indecreasingorder
for(intk=rows; k>=i;k--)
{
System.out.print("*");
}
//Printspace inincreasingorder
for(intj=1; j<i;j++)
{
System.out.print("");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
****
***
**
*
Pattern4:
importjava.util.Scanner;
publicclassPattern4
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace inincreasingorder
for(intj=1; j<i;j++)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk=rows; k>=i;k--)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
****
***
**
*
Pattern5: [ PyramidStar Pattern]
importjava.util.Scanner;
publicclassPattern5
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace indecreasingorder
for(intj=rows;j>i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk=1; k<=(i * 2) -1; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
***
*****
*******
*********
Pattern6:
importjava.util.Scanner;
publicclassPattern6
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=rows;i>=1; i--)
{
//Printstar indecreasingorder
for(intk=1; k<=(i * 2) -1; k++)
{
System.out.print("*");
}
System.out.println();
//Printspace inincreasingorder
for(intj=rows;j>=i; j--)
{
System.out.print("");
}
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*********
*******
*****
***
*
Pattern7: [DiamondStarPattern]
importjava.util.Scanner;
publicclassPattern7
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern ");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace indecreasingorder
for(intj=rows;j>i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk=1; k<=(i * 2) -1; k++)
{
System.out.print("*");
}
System.out.println();
}
for(inti=rows-1;i>=1; i--)
{
// Printspace inincreasingorder
for(intj=rows-1;j>=i; j--)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk=1; k<=(i * 2) -1; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
***
*****
*******
*********
*******
*****
***
*
Pattern8:
importjava.util.Scanner;
publicclassPattern8
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj = 1; j <= i; j++)
{
System.out.print("*");
}
System.out.println();
}
for(inti=1; i<=rows-1; i++)
{
//Printstar indecreasingorder
for(intj = rows-1;j >= i;j--)
{
System.out.print("*");
}
//Printspace inincreasingorder
for(intk = 1; k< i; k++)
{
System.out.print("");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
***
****
*****
****
***
**
*
Pattern9:
importjava.util.Scanner;
publicclassPattern9
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
//Printspace indecreasingorder
for(intj = rows;j > i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk = 1; k<= i; k++)
{
System.out.print("*");
}
System.out.println();
}
for(inti = 1; i <= rows-1;i++)
{
//Printspace inincreasingorder
for(intj = 1; j <= i; j++)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk = rows-1;k >= i; k--)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
***
****
*****
****
***
**
*
Pattern10:
package com.javainterviewpoint;
importjava.util.Scanner;
publicclassPattern10
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = rows-1;j>=i; j--)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk = 1; k<= rows; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
*****
*****
*****
*****
Pattern11:
importjava.util.Scanner;
publicclassPattern11
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = 1; j <= i-1; j++)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk = 1; k<= rows; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
*****
*****
*****
*****
Pattern12:
importjava.util.Scanner;
publicclassPattern12
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = rows; i >= 1; i--)
{
for(intj = i;j >= 1; j--)
{
System.out.print("*");
}
System.out.println();
}
for(inti = 2; i <= rows;i++)
{
for(intj = i;j >= 1; j--)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
****
***
**
*
**
***
****
*****
Pattern13:
importjava.util.Scanner;
publicclassPattern13
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = 1; j < i;j++)
{
System.out.print("");
}
for(intk = i;k <= rows; k++)
{
System.out.print("*");
}
System.out.println();
}
for(inti = rows-1; i >= 1; i--)
{
for(intj = 2; j <=i; j++)
{
System.out.print("");
}
for(intk = i;k <= rows; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
****
***
**
*
**
***
****
*****
Pattern14:
importjava.util.Scanner;
publicclassPattern14
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = 1; j < i;j++)
{
System.out.print("");
}
for(intk = i;k <= rows; k++)
{
System.out.print("*");
}
System.out.println();
}
for(inti = rows-1; i >= 1; i--)
{
for(intj = 1; j < i;j++)
{
System.out.print("");
}
for(intk = i;k <= rows; k++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
Pattern15:
importjava.util.Scanner;
publicclassPattern15
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj=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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
* *
* *
*****
Pattern16:
importjava.util.Scanner;
publicclassPattern16
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace indecreasingorder
for(intj=rows;j>i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk=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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
* *
* *
*****
Pattern17:
importjava.util.Scanner;
publicclassPattern17
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printstar indecreasingorder
for(intj=rows;j >=i; j--)
{
if( i == 1 || j == i || j == rows)
System.out.print("*");
else
System.out.print("");
}
//Printspace inincreasingorder
for(intk=1; k<i;k++)
{
System.out.print("");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
* *
* *
**
*
Pattern18:
importjava.util.Scanner;
publicclassPattern18
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace inincreasingorder
for(intj=1; j<i;j++)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk=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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
* *
* *
**
*
Pattern19:
importjava.util.Scanner;
publicclassPattern19
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace indecreasingorder
for(intj=rows;j>i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk=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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
* *
* *
* *
*********
Pattern20:
importjava.util.Scanner;
publicclassPattern20
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=rows;i>=1; i--)
{
//Printstar indecreasingorder
for(intj=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();
//Printspace inincreasingorder
for(intk = rows; k >= i; k--)
{
System.out.print("");
}
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*********
* *
* *
* *
*
Pattern21:
importjava.util.Scanner;
publicclassPattern21
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
//Printspace indecreasingorder
for(intj=rows;j>i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk=1; k<=(i * 2) -1; k++)
{
if( k == 1 || k == (i * 2) -1)
System.out.print("*");
else
System.out.print("");
}
System.out.println();
}
for(inti=rows-1;i>=1; i--)
{
// Printspace inincreasingorder
for(intj=rows-1;j>=i; j--)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk=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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
* *
* *
* *
* *
* *
* *
* *
*
Pattern22:
importjava.util.Scanner;
publicclassPattern22
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj=1; j<=i;j++)
{
if( j == 1 || j == i )
System.out.print("*");
else
System.out.print("");
}
System.out.println();
}
for(inti=1; i<=rows-1; i++)
{
//Printstar indecreasingorder
for(intj = rows-1;j >= i;j--)
{
if( j == rows-1 || j == i || i == rows)
System.out.print("*");
else
System.out.print("");
}
//Printspace inincreasingorder
for(intk = 1; k< i; k++)
{
System.out.print("");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
* *
* *
* *
* *
* *
**
*
Pattern23:
importjava.util.Scanner;
publicclassPattern23
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
//Printspace indecreasingorder
for(intj = rows;j > i; j--)
{
System.out.print("");
}
//Printstar inincreasingorder
for(intk = 1; k<= i; k++)
{
if( k == 1 || k == i )
System.out.print("*");
else
System.out.print("");
}
System.out.println();
}
for(inti = 1; i <= rows-1;i++)
{
//Printspace inincreasingorder
for(intj = 1; j <= i; j++)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk = 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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
**
* *
* *
* *
* *
* *
**
*
Pattern24:
importjava.util.Scanner;
publicclassPattern24
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = rows-1;j>=i; j--)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk = 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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
* *
* *
* *
*****
Pattern25:
importjava.util.Scanner;
publicclassPattern25
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = 1; j <= i-1; j++)
{
System.out.print("");
}
//Printstar indecreasingorder
for(intk = 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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
* *
* *
* *
*****
Pattern26:
importjava.util.Scanner;
publicclassPattern26
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj = 1; j <= i; j++)
{
System.out.print("*");
}
for(intk = i*2; k <= rows*2-1; k++)
{
System.out.print("");
}
for(intl = 1; l <= i;l++)
{
System.out.print("*");
}
System.out.println();
}
for(inti=1; i<=rows-1; i++)
{
for(intj = rows-1;j >= i;j--)
{
System.out.print("*");
}
for(intk = 1; k<= i*2; k++)
{
System.out.print("");
}
for(intl = rows-1;l >= i; l--)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
* *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *
Pattern27:
importjava.util.Scanner;
publicclassPattern27
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj = i;j <= rows;j++)
{
System.out.print("*");
}
for(intk = 1; k<= i*2-2; k++)
{
System.out.print("");
}
for(intl = i;l <= rows;l++)
{
System.out.print("*");
}
System.out.println();
}
for(inti = 1; i <= rows;i++)
{
for(intj = 1; j <= i; j++)
{
System.out.print("*");
}
for(intk = i*2-2; k < rows*2-2; k++)
{
System.out.print("");
}
for(intl = 1; l <= i;l++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
**********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********
Pattern28:
importjava.util.Scanner;
publicclassPattern28
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= new Scanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti=1; i<=rows; i++)
{
for(intj=rows;j>i; j--)
{
System.out.print("");
}
for(intk=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(inti=rows-1;i>=1; i--)
{
for(intj=rows-1;j>=i; j--)
{
System.out.print("");
}
for(intk=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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*
* *
* *
* *
* *
* *
* *
* *
*
Pattern29:
importjava.util.Scanner;
publicclassPattern29
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
for(inti = 1; i <= rows;i++)
{
for(intj = 1; j < i;j++)
{
System.out.print("");
}
for(intk = i;k <= rows; k++)
{
if( i == 1 || k == i ||k == rows)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
for(inti = rows-1; i >= 1; i--)
{
for(intj = 1; j < i;j++)
{
System.out.print("");
}
for(intk = 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 numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
* * * * *
* *
* *
* *
*
* *
* *
* *
* * * * *
Pattern30:
importjava.util.Scanner;
publicclassPattern30
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj=1; j<=rows;j++)
{
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtoprintthe pattern
5
## Printingthe pattern##
*****
*****
*****
*****
*****
Pattern31:
importjava.util.Scanner;
publicclassPattern31
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=rows; i++)
{
for(intj=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 numberof rowsneededtoprintthe pattern
5
## Printstar patterninjava ##
*****
* *
* *
* *
*****
Pattern32:
importjava.util.Scanner;
publicclassPattern32
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtointhe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=(rows* 2 -1);i++)
{
for(intj=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 numberof rowsneededtointhe pattern
5
## Printtriangle of starsin java##
* *
* *
*
* *
* *
Pattern33:
importjava.util.Scanner;
publicclassPattern33
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe number of rowsneededtointhe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1; i<=(rows* 2 -1);i++)
{
if( i == rows)
{
// PrintingHorizontal Line of Stars
for (intj=1; j<=(rows* 2 -1); j++)
{
System.out.print("*");
}
}
else
{
// Printingspace before Vertical Line of Stars
for(intk=1; k<= rows-1; k++)
{
System.out.print("");
}
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtointhe pattern
5
## Printingthe pattern##
*
*
*
*
*********
*
*
*
*
Pattern34:
importjava.util.Scanner;
publicclassPattern34
{
publicstaticvoidmain(String[] args)
{
//Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtointhe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti = 1; i <= rows* 2 - 1; i++)
{
if (i == 1 || i == rows ||i == rows* 2 - 1)
{
for (intj = 1; j <= rows; j++)
{
if (j == 1 || j == rows)
System.out.print("");
else
System.out.print("*");
}
}
else
{
for (intk= 1; k <= rows;k++)
{
if (k== 1 ||k == rows)
System.out.print("*");
else
System.out.print("");
}
}
System.out.println();
}
scanner.close();
}
}
Output
Enter the numberof rowsneededtointhe pattern
5
## Printingthe pattern##
***
* *
* *
* *
***
* *
* *
* *
***
Pattern35:
importjava.util.Scanner;
publicclassPattern35
{
publicstaticvoidmain(String[] args)
{
// Create a newScannerobject
Scannerscanner= newScanner(System.in);
//Get the numberof rows fromthe user
System.out.println("Enterthe numberof rowsneededtointhe pattern");
introws= scanner.nextInt();
System.out.println("##Printingthe pattern##");
//Printi numberof stars
for(inti=1;i<= rows; i++)
{
if(i%2!=0)
{
for(intj=1; j<= rows/2+1; j++)
{
System.out.print("* ");
}
}
else
{
for(intj=1; j<= rows/2;j++)
{
System.out.print("*");
}
}
System.out.println("");
}
}
}
Output
Enter the numberof rowsneededtointhe pattern
5
## Printingthe pattern##
* * *
* *
* * *
* *
* * *
FiledUnder:Java,JavaInterview
TaggedWith: Diamondpattern,Half DiamondPattern,Hollow Triangle Pattern,InvertedPyramid,Java
Star PatternProgram,Pyramidpattern,RightTriangle Pattern,StarPatternProgramStar Pattern,
Triangle Pattern

More Related Content

PDF
Star pattern programs in java Print Star pattern in java and print triangle ...
KEY
Djangocon11: Monkeying around at New Relic
DOCX
Java file
PDF
Java_practical_handbook
PDF
How to fake_properly
PDF
Managing Mocks
PDF
Java Concurrency by Example
DOCX
201913046 wahyu septiansyah network programing
Star pattern programs in java Print Star pattern in java and print triangle ...
Djangocon11: Monkeying around at New Relic
Java file
Java_practical_handbook
How to fake_properly
Managing Mocks
Java Concurrency by Example
201913046 wahyu septiansyah network programing

What's hot (7)

PPTX
Unit testing without Robolectric, Droidcon Berlin 2016
PPTX
Demystifying dependency Injection: Dagger and Toothpick
PDF
Server1
PPTX
Exceptional exceptions
PDF
The amazing world behind your ORM
PDF
Unit testing without Robolectric, Droidcon Berlin 2016
Demystifying dependency Injection: Dagger and Toothpick
Server1
Exceptional exceptions
The amazing world behind your ORM
Ad

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)

PPTX
Computer programming 2 chapter 1-lesson 2
PDF
3.Lesson Plan - Input.pdf.pdf
PDF
djkkfhulkgyftfdtrdrsdsjjjjjjjjjjjjjjjjjjj
DOCX
How to get input from usjer in Java.docx
PPTX
Presentation1 computer shaan
DOC
Java final lab
PDF
Java Practical File Diploma
PDF
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
DOCX
java program assigment -1
PPTX
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
PPTX
Lab101.pptx
PPTX
Lab01.pptx
DOCX
Java file
PDF
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
DOCX
Transaction Management Tool
PDF
java-programming.pdf
DOCX
Import java
PDF
Java Unit 1 Project
DOCX
import java.uti-WPS Office.docx
PDF
Computer java programs
Computer programming 2 chapter 1-lesson 2
3.Lesson Plan - Input.pdf.pdf
djkkfhulkgyftfdtrdrsdsjjjjjjjjjjjjjjjjjjj
How to get input from usjer in Java.docx
Presentation1 computer shaan
Java final lab
Java Practical File Diploma
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
java program assigment -1
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Lab101.pptx
Lab01.pptx
Java file
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
Transaction Management Tool
java-programming.pdf
Import java
Java Unit 1 Project
import java.uti-WPS Office.docx
Computer java programs
Ad

Recently uploaded (20)

PPT
E commerce busin and some important issues
PDF
THE EFFECT OF FOREIGN AID ON ECONOMIC GROWTH IN ETHIOPIA
PDF
ABriefOverviewComparisonUCP600_ISP8_URDG_758.pdf
PPTX
The discussion on the Economic in transportation .pptx
PDF
Dr Tran Quoc Bao the first Vietnamese speaker at GITEX DigiHealth Conference ...
PDF
Why Ignoring Passive Income for Retirees Could Cost You Big.pdf
PPTX
OAT_ORI_Fed Independence_August 2025.pptx
PPTX
Basic Concepts of Economics.pvhjkl;vbjkl;ptx
PPTX
Session 3. Time Value of Money.pptx_finance
PDF
Understanding University Research Expenditures (1)_compressed.pdf
PPTX
Session 14-16. Capital Structure Theories.pptx
PDF
Dialnet-DynamicHedgingOfPricesOfNaturalGasInMexico-8788871.pdf
PDF
ECONOMICS AND ENTREPRENEURS LESSONSS AND
PDF
Predicting Customer Bankruptcy Using Machine Learning Algorithm research pape...
PPTX
Antihypertensive_Drugs_Presentation_Poonam_Painkra.pptx
PDF
ECONOMICS AND ENTREPRENEURS LESSONSS AND
PPTX
social-studies-subject-for-high-school-globalization.pptx
PDF
caregiving tools.pdf...........................
PPTX
Session 11-13. Working Capital Management and Cash Budget.pptx
PDF
Buy Verified Stripe Accounts for Sale - Secure and.pdf
E commerce busin and some important issues
THE EFFECT OF FOREIGN AID ON ECONOMIC GROWTH IN ETHIOPIA
ABriefOverviewComparisonUCP600_ISP8_URDG_758.pdf
The discussion on the Economic in transportation .pptx
Dr Tran Quoc Bao the first Vietnamese speaker at GITEX DigiHealth Conference ...
Why Ignoring Passive Income for Retirees Could Cost You Big.pdf
OAT_ORI_Fed Independence_August 2025.pptx
Basic Concepts of Economics.pvhjkl;vbjkl;ptx
Session 3. Time Value of Money.pptx_finance
Understanding University Research Expenditures (1)_compressed.pdf
Session 14-16. Capital Structure Theories.pptx
Dialnet-DynamicHedgingOfPricesOfNaturalGasInMexico-8788871.pdf
ECONOMICS AND ENTREPRENEURS LESSONSS AND
Predicting Customer Bankruptcy Using Machine Learning Algorithm research pape...
Antihypertensive_Drugs_Presentation_Poonam_Painkra.pptx
ECONOMICS AND ENTREPRENEURS LESSONSS AND
social-studies-subject-for-high-school-globalization.pptx
caregiving tools.pdf...........................
Session 11-13. Working Capital Management and Cash Budget.pptx
Buy Verified Stripe Accounts for Sale - Secure and.pdf

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 PatternProgramsIn Java | PatternProgram In thisarticle,we will learntoprintthe differentStarPatternProgramsinJava.Thisis one of the popular Java patternprograminterviewquestionforfresher.The patternprogramare the mostrecommended programsto enhance the logical thinkingandforthe betterunderstandingof flow control.Letslookinto the belowpossibleStarPatternProgramsinJavawhichmighthelpforboth the fr Star PatternProgramsIn Java Star PatternProgramsIn Java 1 Star PatternProgramsIn Java 3 Star PatternProgramsIn Java Pattern1: package com.javainterviewpoint; importjava.util.Scanner; publicclassPattern1 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##");
  • 2. //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj=1; j<=i;j++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** *** **** ***** Pattern2: importjava.util.Scanner; publicclassPattern2 {
  • 3. publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace indecreasingorder for(intj=rows;j>i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk=1; k<=i; k++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output
  • 4. Enter the numberof rowsneededtoprint the pattern 5 ## Printingthe pattern## * ** *** **** ***** Pattern3: importjava.util.Scanner; publicclassPattern3 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printstar indecreasingorder
  • 5. for(intk=rows; k>=i;k--) { System.out.print("*"); } //Printspace inincreasingorder for(intj=1; j<i;j++) { System.out.print(""); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** **** *** ** * Pattern4: importjava.util.Scanner;
  • 6. publicclassPattern4 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace inincreasingorder for(intj=1; j<i;j++) { System.out.print(""); } //Printstar indecreasingorder for(intk=rows; k>=i;k--) { System.out.print("*"); } System.out.println(); } scanner.close(); }
  • 7. } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** **** *** ** * Pattern5: [ PyramidStar Pattern] importjava.util.Scanner; publicclassPattern5 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++)
  • 8. { //Printspace indecreasingorder for(intj=rows;j>i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk=1; k<=(i * 2) -1; k++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * *** ***** ******* ********* Pattern6:
  • 9. importjava.util.Scanner; publicclassPattern6 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=rows;i>=1; i--) { //Printstar indecreasingorder for(intk=1; k<=(i * 2) -1; k++) { System.out.print("*"); } System.out.println(); //Printspace inincreasingorder for(intj=rows;j>=i; j--) { System.out.print(""); }
  • 10. } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ********* ******* ***** *** * Pattern7: [DiamondStarPattern] importjava.util.Scanner; publicclassPattern7 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern ");
  • 11. introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace indecreasingorder for(intj=rows;j>i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk=1; k<=(i * 2) -1; k++) { System.out.print("*"); } System.out.println(); } for(inti=rows-1;i>=1; i--) { // Printspace inincreasingorder for(intj=rows-1;j>=i; j--) { System.out.print(""); } //Printstar indecreasingorder for(intk=1; k<=(i * 2) -1; k++) { System.out.print("*");
  • 12. } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * *** ***** ******* ********* ******* ***** *** * Pattern8: importjava.util.Scanner; publicclassPattern8 { publicstaticvoidmain(String[] args)
  • 13. { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } for(inti=1; i<=rows-1; i++) { //Printstar indecreasingorder for(intj = rows-1;j >= i;j--) { System.out.print("*"); } //Printspace inincreasingorder for(intk = 1; k< i; k++)
  • 14. { System.out.print(""); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** *** **** ***** **** *** ** * Pattern9: importjava.util.Scanner;
  • 15. publicclassPattern9 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { //Printspace indecreasingorder for(intj = rows;j > i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk = 1; k<= i; k++) { System.out.print("*"); } System.out.println(); } for(inti = 1; i <= rows-1;i++) {
  • 16. //Printspace inincreasingorder for(intj = 1; j <= i; j++) { System.out.print(""); } //Printstar indecreasingorder for(intk = rows-1;k >= i; k--) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** *** **** ***** **** *** ** *
  • 17. Pattern10: package com.javainterviewpoint; importjava.util.Scanner; publicclassPattern10 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = rows-1;j>=i; j--) { System.out.print(""); } //Printstar indecreasingorder for(intk = 1; k<= rows; k++) { System.out.print("*"); }
  • 18. System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** ***** ***** ***** ***** Pattern11: importjava.util.Scanner; publicclassPattern11 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user
  • 19. System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = 1; j <= i-1; j++) { System.out.print(""); } //Printstar indecreasingorder for(intk = 1; k<= rows; k++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** ***** *****
  • 20. ***** ***** Pattern12: importjava.util.Scanner; publicclassPattern12 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = rows; i >= 1; i--) { for(intj = i;j >= 1; j--) { System.out.print("*"); } System.out.println(); }
  • 21. for(inti = 2; i <= rows;i++) { for(intj = i;j >= 1; j--) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** **** *** ** * ** *** **** ***** Pattern13:
  • 22. importjava.util.Scanner; publicclassPattern13 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = 1; j < i;j++) { System.out.print(""); } for(intk = i;k <= rows; k++) { System.out.print("*"); } System.out.println(); }
  • 23. for(inti = rows-1; i >= 1; i--) { for(intj = 2; j <=i; j++) { System.out.print(""); } for(intk = i;k <= rows; k++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** **** *** ** * ** *** ****
  • 24. ***** Pattern14: importjava.util.Scanner; publicclassPattern14 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = 1; j < i;j++) { System.out.print(""); } for(intk = i;k <= rows; k++) { System.out.print("*");
  • 25. } System.out.println(); } for(inti = rows-1; i >= 1; i--) { for(intj = 1; j < i;j++) { System.out.print(""); } for(intk = i;k <= rows; k++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * * * * * * * * * * * * * * *
  • 26. * * * * * * * * * * * * * * Pattern15: importjava.util.Scanner; publicclassPattern15 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj=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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** * * * * ***** Pattern16: importjava.util.Scanner; publicclassPattern16 { publicstaticvoidmain(String[] args) {
  • 28. //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace indecreasingorder for(intj=rows;j>i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk=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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** * * * * ***** Pattern17: importjava.util.Scanner; publicclassPattern17 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##");
  • 30. for(inti=1; i<=rows; i++) { //Printstar indecreasingorder for(intj=rows;j >=i; j--) { if( i == 1 || j == i || j == rows) System.out.print("*"); else System.out.print(""); } //Printspace inincreasingorder for(intk=1; k<i;k++) { System.out.print(""); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** * * * *
  • 31. ** * Pattern18: importjava.util.Scanner; publicclassPattern18 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace inincreasingorder for(intj=1; j<i;j++) { System.out.print(""); } //Printstar indecreasingorder
  • 32. for(intk=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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** * * * * ** * Pattern19: importjava.util.Scanner; publicclassPattern19
  • 33. { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace indecreasingorder for(intj=rows;j>i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk=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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * * * * * * * ********* Pattern20: importjava.util.Scanner; publicclassPattern20 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern");
  • 35. introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=rows;i>=1; i--) { //Printstar indecreasingorder for(intj=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(); //Printspace inincreasingorder for(intk = rows; k >= i; k--) { System.out.print(""); } } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5
  • 36. ## Printingthe pattern## ********* * * * * * * * Pattern21: importjava.util.Scanner; publicclassPattern21 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { //Printspace indecreasingorder for(intj=rows;j>i; j--)
  • 37. { System.out.print(""); } //Printstar inincreasingorder for(intk=1; k<=(i * 2) -1; k++) { if( k == 1 || k == (i * 2) -1) System.out.print("*"); else System.out.print(""); } System.out.println(); } for(inti=rows-1;i>=1; i--) { // Printspace inincreasingorder for(intj=rows-1;j>=i; j--) { System.out.print(""); } //Printstar indecreasingorder for(intk=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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * * * * * * * * * * * * * * * * Pattern22: importjava.util.Scanner; publicclassPattern22 { publicstaticvoidmain(String[] args)
  • 39. { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj=1; j<=i;j++) { if( j == 1 || j == i ) System.out.print("*"); else System.out.print(""); } System.out.println(); } for(inti=1; i<=rows-1; i++) { //Printstar indecreasingorder for(intj = rows-1;j >= i;j--) { if( j == rows-1 || j == i || i == rows)
  • 40. System.out.print("*"); else System.out.print(""); } //Printspace inincreasingorder for(intk = 1; k< i; k++) { System.out.print(""); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** * * * * * * * * * * ** *
  • 41. Pattern23: importjava.util.Scanner; publicclassPattern23 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { //Printspace indecreasingorder for(intj = rows;j > i; j--) { System.out.print(""); } //Printstar inincreasingorder for(intk = 1; k<= i; k++) {
  • 42. if( k == 1 || k == i ) System.out.print("*"); else System.out.print(""); } System.out.println(); } for(inti = 1; i <= rows-1;i++) { //Printspace inincreasingorder for(intj = 1; j <= i; j++) { System.out.print(""); } //Printstar indecreasingorder for(intk = 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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * ** * * * * * * * * * * ** * Pattern24: importjava.util.Scanner; publicclassPattern24 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt();
  • 44. System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = rows-1;j>=i; j--) { System.out.print(""); } //Printstar indecreasingorder for(intk = 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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** * * * *
  • 45. * * ***** Pattern25: importjava.util.Scanner; publicclassPattern25 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = 1; j <= i-1; j++) { System.out.print(""); } //Printstar indecreasingorder for(intk = 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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** * * * * * * ***** Pattern26: importjava.util.Scanner; publicclassPattern26 {
  • 47. publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj = 1; j <= i; j++) { System.out.print("*"); } for(intk = i*2; k <= rows*2-1; k++) { System.out.print(""); } for(intl = 1; l <= i;l++) { System.out.print("*"); } System.out.println(); }
  • 48. for(inti=1; i<=rows-1; i++) { for(intj = rows-1;j >= i;j--) { System.out.print("*"); } for(intk = 1; k<= i*2; k++) { System.out.print(""); } for(intl = rows-1;l >= i; l--) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * * ** ** *** *** **** ****
  • 49. ********** **** **** *** *** ** ** * * Pattern27: importjava.util.Scanner; publicclassPattern27 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj = i;j <= rows;j++) {
  • 50. System.out.print("*"); } for(intk = 1; k<= i*2-2; k++) { System.out.print(""); } for(intl = i;l <= rows;l++) { System.out.print("*"); } System.out.println(); } for(inti = 1; i <= rows;i++) { for(intj = 1; j <= i; j++) { System.out.print("*"); } for(intk = i*2-2; k < rows*2-2; k++) { System.out.print(""); } for(intl = 1; l <= i;l++) { System.out.print("*"); } System.out.println();
  • 51. } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ********** **** **** *** *** ** ** * * * * ** ** *** *** **** **** ********** Pattern28: importjava.util.Scanner; publicclassPattern28 { publicstaticvoidmain(String[] args) {
  • 52. //Create a newScannerobject Scannerscanner= new Scanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti=1; i<=rows; i++) { for(intj=rows;j>i; j--) { System.out.print(""); } for(intk=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(inti=rows-1;i>=1; i--) { for(intj=rows-1;j>=i; j--) { System.out.print("");
  • 53. } for(intk=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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * * * * * * * * * * * * * * * * Pattern29:
  • 54. importjava.util.Scanner; publicclassPattern29 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); for(inti = 1; i <= rows;i++) { for(intj = 1; j < i;j++) { System.out.print(""); } for(intk = i;k <= rows; k++) { if( i == 1 || k == i ||k == rows) System.out.print("*"); else
  • 55. System.out.print(" "); } System.out.println(); } for(inti = rows-1; i >= 1; i--) { for(intj = 1; j < i;j++) { System.out.print(""); } for(intk = 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 numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## * * * * *
  • 56. * * * * * * * * * * * * * * * * * * Pattern30: importjava.util.Scanner; publicclassPattern30 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++)
  • 57. { for(intj=1; j<=rows;j++) { System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtoprintthe pattern 5 ## Printingthe pattern## ***** ***** ***** ***** ***** Pattern31: importjava.util.Scanner; publicclassPattern31 { publicstaticvoidmain(String[] args)
  • 58. { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtoprintthe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=rows; i++) { for(intj=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 numberof rowsneededtoprintthe pattern 5
  • 59. ## Printstar patterninjava ## ***** * * * * * * ***** Pattern32: importjava.util.Scanner; publicclassPattern32 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtointhe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=(rows* 2 -1);i++) { for(intj=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 numberof rowsneededtointhe pattern 5 ## Printtriangle of starsin java## * * * * * * * * * Pattern33: importjava.util.Scanner;
  • 61. publicclassPattern33 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe number of rowsneededtointhe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1; i<=(rows* 2 -1);i++) { if( i == rows) { // PrintingHorizontal Line of Stars for (intj=1; j<=(rows* 2 -1); j++) { System.out.print("*"); } } else { // Printingspace before Vertical Line of Stars for(intk=1; k<= rows-1; k++) {
  • 62. System.out.print(""); } System.out.print("*"); } System.out.println(); } scanner.close(); } } Output Enter the numberof rowsneededtointhe pattern 5 ## Printingthe pattern## * * * * ********* * * * * Pattern34: importjava.util.Scanner;
  • 63. publicclassPattern34 { publicstaticvoidmain(String[] args) { //Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtointhe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti = 1; i <= rows* 2 - 1; i++) { if (i == 1 || i == rows ||i == rows* 2 - 1) { for (intj = 1; j <= rows; j++) { if (j == 1 || j == rows) System.out.print(""); else System.out.print("*"); } } else { for (intk= 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 numberof rowsneededtointhe pattern 5 ## Printingthe pattern## *** * * * * * * *** * * * * * * *** Pattern35:
  • 65. importjava.util.Scanner; publicclassPattern35 { publicstaticvoidmain(String[] args) { // Create a newScannerobject Scannerscanner= newScanner(System.in); //Get the numberof rows fromthe user System.out.println("Enterthe numberof rowsneededtointhe pattern"); introws= scanner.nextInt(); System.out.println("##Printingthe pattern##"); //Printi numberof stars for(inti=1;i<= rows; i++) { if(i%2!=0) { for(intj=1; j<= rows/2+1; j++) { System.out.print("* "); } } else {
  • 66. for(intj=1; j<= rows/2;j++) { System.out.print("*"); } } System.out.println(""); } } } Output Enter the numberof rowsneededtointhe pattern 5 ## Printingthe pattern## * * * * * * * * * * * * * FiledUnder:Java,JavaInterview TaggedWith: Diamondpattern,Half DiamondPattern,Hollow Triangle Pattern,InvertedPyramid,Java Star PatternProgram,Pyramidpattern,RightTriangle Pattern,StarPatternProgramStar Pattern, Triangle Pattern