PYRAMID PATTERNS
MORE PATTERNS ARE COMING ON THE WAY
*
* *
* * *
* * * *
* * * * *
1. public class PATTERN1 {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; ++i) {
for (int j = 1; j <= i; ++j) {
System.out.print("* ");
}
System.out.println();
}
}
}
* * * * *
* * * *
* * *
* *
*
2.
public class PATTREN2 {
public static void main(String[] args) {
int rows = 5;
for (int i = rows; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
System.out.print("* ");
}
System.out.println();
}
}
}
**
* *
* *
* *
**
*
3. public class PATTERN3
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter N : ");
int n=sc.nextInt();
int i=n;
int j;
while(i>0)
{
if(i==1 || i==n)
{
j=1;
while(j <=i)
{
System.out.print("*");
j++;
}
}
else
{
j=1;
while(j<=i)
{
if(j==1 || j==i)
System.out.print("*");
else
System.out.print(" ");
j++;
}
}
System.out.println();
i--;
}
}
}
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
4.
public class PATTERN4 {
public static void main(String[] args) {
int rows = 5, k = 0;
for (int i = 1; i <= rows; ++i, k = 0) {
for (int space = 1; space <= rows - i; ++space) {
System.out.print(" ");
}
while (k != 2 * i - 1) {
System.out.print("* ");
++k;
}
System.out.println();
}
}
}
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
5.
public class PATTERN5 {
public static void main(String[] args) {
int rows = 5;
for(int i = rows; i >= 1; --i) {
for(int space = 1; space <= rows - i; ++space) {
System.out.print(" ");
}
for(int j=i; j <= 2 * i - 1; ++j) {
System.out.print("* ");
}
for(int j = 0; j < i - 1; ++j) {
System.out.print("* ");
}
System.out.println();
}
}
}
*
* *
* *
* *
* *
* *
* *
* *
* *
*******
6.
class pattern6
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter N : ");
int n=sc.nextInt();
System.out.print("Enter Symbol : ");
char c = sc.next().charAt(0);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n-i;j++)
{
System.out.print(" ");
}
if(i==1 || i==n)
for(int j=1;j<=i*2-1;j++)
{
System.out.print(c);
}
else
{
for(int j=1;j<=i*2-1;j++)
{
if(j==1 || j==i*2-1)
System.out.print(c);
else
System.out.print(" ");
}
}
System.out.println();
}
}
}