0% found this document useful (0 votes)
13 views

Pattern Program

Uploaded by

tcsplams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Pattern Program

Uploaded by

tcsplams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

What is pattern program ?

Pattern programs are nothing but patterns consisting of numbers, alphabets or


symbols in a particular form. These kinds of pattern programs can be solved easily
using for loop condition.

Here we use FOR loop mainly.


Pattern 01
Print single star
class Pattern_01
{
public static void main(String [] args)
{
System.out.print("*");
}
}

Pattern 02
Print 5 stars in row
class Pattern_02
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
System.out.print("*");
}
}
}
Pattern 03
Print 5 stars in column
class Pattern_03
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
System.out.println("*");
}
}
}
Pattern 04
Print the pattern given below
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Number of rows(i) Number of stars (j)
1 5
2 5
3 5
4 5
5 5

class Pattern_04
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int j=1; j<=5; j++)
{
System.out.print("*");
}
System.out.println( );

}
}
}

Pattern 05
Print the pattern given below
*
* *
* * *
* * * *
* * * * *
Number of rows(i) Number of stars (j)
1 1
2 2
3 3
4 4
5 5

class Pattern_05
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}

CONTINUE
Pattern 06
Print the pattern below
*****
****
***
**
*
Number of rows (i) Number of stars(j)
1 5
2 4
3 3
4 2
5 1

class Pattern_06
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int j=i; j<=5; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}

Pattern 07
Print the pattern below
_____*****
_____*****
_____*****
_____*****
_____*****
Number of rows (i) Number of spaces (k) Number of stars (j)
1 5 5
2 5 5
3 5 5
4 5 5
5 5 5

class Pattern_07
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int k=1; k<=5; k++)
{
System.out.print(" ");
}
for(int j=1; j<=5; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}
Pattern 08
Print the pattern below
_____*
____**
___***
__****
_*****
Number of rows (i) Number of spaces (k) Number of stars (j)
1 5 1
2 4 2
3 3 3
4 2 4
5 1 5

class Pattern_08
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int k=i; k<=5; k++)
{
System.out.print(" ");
}
for(int j=1; j<=i; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}

Pattern 09
Print the pattern below
_* * * * *
_ _* * * *
_ _ _* * *
_ _ _ _* *
_ _ _ _ _*
Number of rows (i) Number of spaces (k) Number of stars (j)
1 1 5
2 2 4
3 3 3
4 4 2
5 5 1
class Pattern_09
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int j=i; j<=5; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}

Pattern 10
Print the pattern below
_* * * * *
_ _* * * * *
_ _ _* * * * *
_ _ _ _* * * * *
_ _ _ _ _* * * * *
Number of rows (i) Number of spaces (k) Number of stars (j)
1 1 5
2 2 5
3 3 5
4 4 5
5 5 5

class Pattern_10
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int j=1; j<=5; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}
CONTINUE
Pattern 11
Print the pattern below
_ _ _ _ _* * * * *
_ _ _ _* * * * *
_ _ _* * * * *
_ _* * * * *
_* * * * *
Number of rows (i) Number of spaces (k) Number of stars (j)
1 5 5
2 4 5
3 3 5
4 2 5
5 1 5

class Pattern_11
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int k=i; k<=5; k++)
{
System.out.print(" ");
}
for(int j=1; j<=5; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}

Pattern 12
Print the pattern below
*
***
*****
*******
*********

Number of rows (i) Number of spaces (k) Number of stars (j)


1 5 1
2 4 3
3 3 5
4 2 7
5 1 9
k <= 5 - i + 1 j <= (2 * i) -1

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

Pattern 13
Print the pattern below
*********
*******
*****
***
*

Number of rows (i) Number of spaces (k) Number of stars (j)


1 1 9
2 2 7
3 3 5
4 4 3
5 5 1
k <= i j <= 11-2*i

class Pattern_13
{
public static void main(String [] args)
{
for(int i=1; i<=5 ; i++)
{
for(int k=1; k<=i; k++)
{
System.out.print(" ");
}
for(int j=i; j<=11-(2*i); j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}
Pattern 14
Print the pattern below
_ _ _ _ _* * * * *
_ _ _ _ _* *
_ _ _ _ _* *
_ _ _ _ _* *
_ _ _ _ _* * * * *

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

Pattern 15
Print the pattern below
*
* *
* *
* *
*********

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

CONTINUE
Pattern 16
Print the pattern below
*********
* *
* *
**
*

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

Pattern 17
Print the pattern below
*
***
*****
*******
*********
*********
*********
*********
*********
*********

class Pattern_17
{
public static void main(String [] args)
{
int i, j, k;
for(i=1; i<=5 ; i++)
{
for(k=1; k<=5-i+1; k++)
{
System.out.print(" ");
}
for(j=1; j<=(2*i)-1; j++)
{
System.out.print("*");
}
System.out.println( );
}
for(i=1; i<=5; i++)
{
System.out.print(" ");
for(j=1; j<=9; j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}
Pattern 18
Print the pattern below
*
***
*****
*******
*********
*******
*****
***
*

class Pattern_18
{
public static void main(String [] args)
{
int i,j,k;
for(i=1; i<=4 ; i++)
{
for(k=1; k<=5-i+1; k++)
{
System.out.print(" ");
}
for(j=1; j<=(2*i)-1; j++)
{
System.out.print("*");
}
System.out.println( );
}
for(i=1; i<=5 ; i++)
{
for(k=1; k<=i; k++)
{
System.out.print(" ");
}
for(j=1; j<=11-(2*i); j++)
{
System.out.print("*");
}
System.out.println( );
}
}
}

Pattern 19
Print the pattern below
*
* *
* *
* *
* *
* *
* *
* *
*

class Pattern_19
{
public static void main(String [] args)
{
int i,j,k;
for(i=1; i<=4 ; i++)
{
for(k=1; k<=5-i+1; k++)
{
System.out.print(" ");
}
for(j=1; j<=(2*i)-1; j++)
{
if(j == 1 || j == (2*i)-1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println( );
}
for(i=1; i<=5 ; i++)
{
for(k=1; k<=i; k++)
{
System.out.print(" ");
}
for(j=1; j<=11-(2*i); j++)
{
if(j == 1 || j == 11-(2*i))
System.out.print("*");
else
System.out.print(" ");
}
System.out.println( );
}
}
}

You might also like