Pattern Programs

 

Java Pattern Programs


package MyJavaPackage;

public class Pattern1 {
public static void main(String[] args) {

char ch='A';
char changeChar='A';
for (int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(j<=i)
{
System.out.print(ch);
ch++;
}
else
{
System.out.print(changeChar);
}
}
ch='A';
changeChar++;
System.out.println();
}
}
}

/*

AAAAA
ABBBB
ABCCC
ABCDD
ABCDE

*/


package MyJavaPackage;

public class Pattern2 {
public static void main(String[] args) {

int change=5;
for (int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(j == change)
System.out.print("*");
else
System.out.print(j);
}
change--;
System.out.println();
}
}
}

/*

1234*
123*5
12*45
1*345
*2345
*/


package MyJavaPackage;

public class Pattern3 {
public static void main(String[] args) {

int number=1;

for(int j=1; j<=25; j++)
{
if(j%2==0)
System.out.print(" "+number++);
else
System.out.print(" *");
if(j%5==0)
System.out.println();
}


}

}

/*
* 1 * 2 *
3 * 4 * 5
* 6 * 7 *
8 * 9 * 10
* 11* 12*

*/


package MyJavaPackage;

public class Pattern4 {
public static void main(String[] args) {

int startStar=1, endStar=7;
for (int i=1; i<=4; i++)
{
for(int j=1; j<=7; j++)
{
if(j==4 || startStar==j || endStar==j)
System.out.print("*");
else
System.out.print(0);

}
startStar++;
endStar--;

System.out.println();
}
}
}

/*

*00*00*
0*0*0*0
00***00
000*000

*/


package MyJavaPackage;

public class Pattern5 {
public static void main(String[] args) {

int column=9;
for (int i=1; i<=5; i++)
{
for(int j=1; j<=column; j++)
{
System.out.print(j);
}
column = column-2;
System.out.println();
}
}
}

/*

123456789
1234567
12345
123
1

*/


package MyJavaPackage;

public class Pattern6 {
public static void main(String[] args) {

int star=5;
for (int i=1; i<=5; i++)
{

for(int space=1; space<i; space++)
{
System.out.print(" ");
}
for(int j=1; j<=star; j++)
{
if(i%2==0)
System.out.print("*");
else
System.out.print("#");
}

star--;
System.out.println();
}
}
}

/*

#####
****
###
**
#

*/


package MyJavaPackage;

public class Pattern7 {


public static void main(String[] args) {
int space = 4;
char ch = '#';

for (int i=1; i<=5; i++)
{
for(int j=1; j<=space; j++)
{
System.out.print(" ");
}
if(space%2==0)
ch = '#';
else
ch = '*';
for(int k=1; k<=i; k++)
{
System.out.print(ch + " ");
if(ch=='#')
ch='*';
else
ch='#';
}
space--;
System.out.println();

}
}
}


/*
#
* #
# * #
* # * #
# * # * #

*/



package MyJavaPackage;

public class Pattern8 {
public static void main(String[] args) {
int space=4;
char ch='A';
int num=1;

for(int i=1; i<=5; i++)
{
for(int k=1; k<=space; k++)
{
System.out.print(" ");
}
for(int j=1; j<=i; j++)
{
if(i%2!=0)
System.out.print(ch+" ");
else
System.out.print(num+" ");
}
space--;
ch++;
num++;
System.out.println();
}
}
}

/*

A
2 2
C C C
4 4 4 4
E E E E E

*/



package MyJavaPackage;

public class Pattern9 {
public static void main(String[] args) {
int space=4;
char ch='A';
int num=1;
int capacity=1;

for(int i=1; i<=5; i++)
{
for(int k=1; k<=space; k++)
{
System.out.print(" ");
}
for(int j=1; j<=capacity; j++)
{
if(i%2==0)
System.out.print(ch++);
else
System.out.print(num++);
}
space--;

capacity+=2;
System.out.println();
}
}
}

/*

1
ABC
23456
DEFGHIJ
789101112131415

*/



package MyJavaPackage;

public class Pattern10 {
public static void main(String[] args) {
int colNum=1;
int rowNum=1;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(j==3 && i!=3)
System.out.print(colNum);
else if(i==3)
System.out.print(rowNum++);
else
System.out.print(" ");
}
colNum++;
System.out.println();
}
}

}


/*

1
2
12345
4
5

*/



package MyJavaPackage;

public class Pattern11 {
public static void main(String[] args) {
int colNum=5;
int rowNum=5;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(j==3 && i!=3)
System.out.print(colNum);
else if(i==3)
{
System.out.print(rowNum);
if(j<3)
rowNum--;
else
rowNum++;

}
else
System.out.print(" ");
}

colNum--;
System.out.println();
}
}

}


/*

5
4
54345
2
1

*/


package MyJavaPackage;

public class Pattern12 {
public static void main(String[] args) {
int colNum=2;
int rowNum=2;
for(int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(j==3 && i!=3)
{
System.out.print(colNum);
if (i < 3)
colNum--;
else
colNum++;

}
else if(i==3 && j==3)
{
System.out.print(rowNum);
colNum++;
rowNum++;

}
else if(i==3 && j!=3)
{
System.out.print(rowNum);
if(j<3)
rowNum--;
else
rowNum++;

}
else
System.out.print(" ");
}


System.out.println();
}
}

}


/*

2
1
21012
1
2

*/



package MyJavaPackage;

public class Pattern13 {
public static void main(String[] args) {

for(int row=1; row<=5; row++)
{
for(int col=5; col>=row; col-- )
{
System.out.print("*");
}
System.out.println();

}

for(int row=1; row<=5; row++)
{
for(int col=1; col<=row; col++ )
{
System.out.print("*");
}
System.out.println();

}

}
}

/*

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

*/



package MyJavaPackage;

public class Pattern14 {
public static void main(String[] args) {
int space=4,star=1;
int num=1;

for(int i=1; i<=5; i++)
{
for(int k=1; k<=space; k++)
{
System.out.print(num++);
}
for(int j=1; j<=star; j++)
{
System.out.print("*");
}
num--;
for(int k=4; k>=i; k--)
{
System.out.print(num--);
}

space--;
num=1;
star+=2;
System.out.println();
}
}
}

/*

1234*4321
123***321
12*****21
1*******1
*********

*/




package MyJavaPackage;

public class Pattern15 {
public static void main(String[] args) {
char ch='A';

for(int i=1; i<=5; i++)
{
for(int j=1; j<=5; j++)
{
if(j<=i)
System.out.print(ch);
else
System.out.print("*");
}
ch++;
System.out.println();
}
}
}

/*

A****
BB***
CCC**
DDDD*
EEEEE

*/



package MyJavaPackage;

public class Pattern16 {
public static void main(String[] args) {
int colNum=0,rowNum=0;
int num=1;

for(int i=0; i<=4; i++)
{
int temp = rowNum;
for(int j=0; j<=4; j++)
{
if(j>=i)
System.out.print(colNum++);
else
{
System.out.print(temp--);
}
}
rowNum++;
colNum=0;
System.out.println();
}
}
}

/*

01234
10123
21012
32101
43210

*/




package MyJavaPackage;

public class Pattern17 {
public static void main(String[] args) {
int capacity=10,num=1,midChange=5;

for(int i=1; i<=5; i++)
{
for(int j=1; j<=midChange; j++)
{
System.out.print(num++);
if(j==midChange)
{
for(int k=midChange; k>=1; k--)
{
System.out.print(k);
}
}
}
num=1;
midChange--;
capacity-=2;
System.out.println();
}
}
}

/*


1234554321
12344321
123321
1221
11

*/






























s























s






































s



































s

Comments

Post a Comment

hey

Popular posts from this blog

Practical slips programs : Machine Learning

Full Stack Developement Practical Slips Programs

Android App Developement Practicals Programs