Pattern print in java
Pattern programs are very good programs for learning loops. These kinds of programs asked in ICSE, ISC, CBSE, BCA exams. In this post, there is several numbers of java pattern program solved with output. Enjoy and learn the pattern in Java.Floyd Triangle in Java
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
public class FloydTriangle
{
public static void main(String args[])
{
int k = 1;
int i, j;
for(i=1;i <=5; i++)
{
for(j=1; j<=i; j++)
{
System.out.print(k + " ");
k++;
}
System.out.println();
}
}
}
54321
4321
321
21
1
public class Pattern
{
public static void main(String args[])
{
int i, j, k;
for(i=5; i>=1; i--)
{
for(j=1; j<=5-i; j++)
{
System.out.print(" ");
}
for(k=i; k>=1; k--)
{
System.out.print(k);
}
System.out.println();
}
}
}
- + - + -
+ - + -
- + -
+ -
-
public class Pattern3
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
if(j%2==0)
System.out.print("+"+" ");
else
System.out.print("-"+" ");
}
System.out.println();
}
}
}
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
public class Pattern1
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
}
}
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
public class Pattern1
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
}
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
public class Pattern2
{
public static void main(String args[])
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
}
}
12345
22345
33345
44445
55555
{
public static void main(String args[])
{
int i;
int j;
int k;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(i);
}
for(k=i+1;k<=5;k++)
{
System.out.print(k);
}
System.out.println();
}
}
}
1
121
12321
1234321
123454321
1234321
12321
121
1
public class Pattern4
{
public static void main(String args[])
{
int i,j,k,n;
for(i=1;i<=5;i++)
{
for(n=1;n<=5-i;n++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print(j);
}
for(k=i-1;k>=1;k--)
{
System.out.print(k);
}
System.out.println();
}
for(i=1;i<=4;i++)
{
for(n=1;n<=i;n++)
{
System.out.print(" ");
}
for(k=1;k<=5-i;k++)
{
System.out.print(k);
}
for(j=4-i;j>=1;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}
0
12
345
6789
543
21
0
0
12
345
6789
543
21
0
class Pattern5
{
public static void main()
{
int i,j,k=0,k2=5;
for(i=1;i<=4;i++)
{
for(j=0;j<i;j++)
{
System.out.print(k);
k++;
}
System.out.println();
}
for(i=3;i>=1;i--)
{
for(j=0;j<i;j++)
{
System.out.print(k2);
k2--;
}
System.out.println();
}
}
}
1 * 1
2 * * 2
3 * * * 3
4 * * * * 4
5 * * * * * 5
public class Pattern
{
public static void main(String args[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=1;j<=5-i;j++)
{
System.out.print(" ");
}
System.out.print(i+" ");
for(k=1;k<=i;k++)
{
System.out.print("* ");
}
System.out.print(i);
System.out.println();
}
}
}