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

Pattern

The document contains 14 Java programs that output different patterns using loops and conditionals. Each program contains a class with a main method that uses nested for loops to print patterns like stars, numbers, letters, or combinations in various arrangements.

Uploaded by

pc651719
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Pattern

The document contains 14 Java programs that output different patterns using loops and conditionals. Each program contains a class with a main method that uses nested for loops to print patterns like stars, numbers, letters, or combinations in various arrangements.

Uploaded by

pc651719
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

* * * * *

* * * * *
* * * * *
* * * * *
* * * * *
class P1
{
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();
}
}
}
******************************************************************************

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

}
System.out.println();

}
}
}

***********************************************************************************
*******************

*
* *
* * *
* * * *
* * * * *
class P3
{
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();
}
}
}
***********************************************************************************
**********************

* * * * *
* * * *
* * *
* *
*

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

for (int i=1;i<=row ;i++ )


{
for (int j=1;j<=row-i ;j++ )
{
System.out.print(" ");
}
for (int k=1;k<=i ;k++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
***********************************************************************************
**********************
1
12
123
1234
12345

class P6
{
public static void main(String[] args)
{
int row=5;
for (int i=1;i<=row ;i++ )
{
for (int j=1;j<=i ;j++ )
{
System.out.print(j);
}
System.out.println();
}
}
}
***********************************************************************************
*****************
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
class P7
{
public static void main(String[] args)
{

int num=1;
for (int i=5;i>=1 ;i-- )
{
for (int j=1;j<=i ;j++ )
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
***********************************************************************************
*******************
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
class P8
{
public static void main(String[] args)
{
int num=1;
for (int i=1;i<=5 ;i++ )
{
for (int j=1;j<=i ;j++ )
{
System.out.print(num+" ");
num++;
}
System.out.println();

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

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

for (int j=1;j<=i ;j++ )


{
System.out.print("*");
}
System.out.println();
}

for (int i=n;i>=1 ;i-- )


{
for (int j=1;j<=i ;j++ )
{
System.out.print("*");
}
//spaces
int spaces = 2*(n-i);
for (int j=1;j<=spaces ; j++)
{
System.out.print(" ");
}

for (int j=1;j<=i ;j++ )


{
System.out.print("*");
}
System.out.println();
}
}
}
***********************************************************************************
***********************************
*****
*****
*****
*****
*****
class P11
{
public static void main(String[] args)
{
int n=5;
for (int i=1;i<=n ;i++ )
{
for (int j=1;j<=n-i ;j++ )
{
System.out.print(" ");
}
for (int j=1;j<=n ;j++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
***********************************************************************************
*********************
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
class P12
{
public static void main(String[] args)
{
int n=5;
for (int i=1;i<=n ;i++ )
{
for (int j=1;j<=n-i ;j++ )
{
System.out.print(" ");
}
for (int j=1;j<=i ;j++ )
{
System.out.print(i+" ");
}
System.out.println();
}
}
}
***********************************************************************************
*******************
1
212
32123
4321234
543212345
class P13
{
public static void main(String[] args)
{
int n=5;
for (int i=1;i<=n ;i++ )
{
for (int j=1;j<=n-i ;j++ )
{
System.out.print(" ");
}
for (int j=i;j>=1 ;j-- )
{
System.out.print(j);

}
for (int j=2;j<=i ;j++ )
{
System.out.print(j);
}
System.out.println();
}
}
}
***********************************************************************************
**********************

*
***
*****
*******
*******
*****
***
*
class P15
{
public static void main(String[] args)
{
int n=4;
for (int i=1;i<=n ;i++ )
{
for (int j=1;j<=n-i ;j++ )
{
System.out.print(" ");
}
//stars
for (int j=1;j<=2*i-1 ;j++ )
{
System.out.print("*");
}
System.out.println();
}

for (int i=n;i>=1 ;i-- )


{
for (int j=1;j<=n-i ;j++ )
{
System.out.print(" ");
}
//stars
for (int j=1;j<=2*i-1 ;j++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
***********************************************************************************
******

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

***********************************************************************************
*********

1
AB
123
ABCD
12345

class P16
{
public static void main(String[] args)
{
int n=5;
for (int i=1;i<=n ;i++ )
{
char ch='A';
int num=1;
for (int j=1;j<=i ;j++ )
{

if (i%2==0)
{
System.out.print(ch);
ch++;
}
else{
System.out.print(num);
num++;
}
}
System.out.println();
}
}
}
***********************************************************************************
*******
*****
****
***
**
*
class P17
{
public static void main(String[] args)
{
int n=5;
char ch ='A';
int num=1;
for (int i=1;i<=n ;i++ )
{
for (int j=1;j<i ;j++ )
{
System.out.print(" ");
}
for (int j=1;j<=n-i+1 ;j++ )
{
System.out.print("*");
}
System.out.println();
}

}
}
***********************************************************************************
******************

You might also like