Interview Pattern Program in java

Pattern 1:
number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package Patternprogram;
 
class pattern1
{
	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((j%2==0)?0+" ":1+" ");
			System.out.println();
		}
	}
}
Pattern 2:
p-1
1
2
3
4
5
6
7
8
9
10
11
12
class pattern11
{
	public static void main(String args[])
	{
		for(int i=5;i>0;i--)
		{
			for(int j=1;j<=i;j++)
				System.out.print("*");
			System.out.println();
		}
	}
}
Pattern 3:
p2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class pattern16
{
	public static void main(String args[])
	{
		for(int i=1;i<=5;i++)
		{
			for(int j=1;j<=5-i;j++)
				System.out.print(" ");
			for(int j=1;j<=2*i-j;j++)
				System.out.print(j+" ");
		System.out.println();
		}
	}
}
Pattern 4:
p3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class pattern17
{
	public static void main(String args[])
	{
		for(int i=1;i<=5;i++)
		{
			for(int j=5;j>=i;j--)
				System.out.print(" ");
			for(int j=1;j<=i;j++)
				System.out.print("*");
			System.out.println();
		}
	}
}
Pattern 5:
p4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package Patternprogram;
 
 
 
class pattern18
{
	public static void main(String args[])
	{
 
		for(int i=0;i<=5;i++)
		{
			for(int j=5;j>i-1;j--)
				System.out.print(" ");
			for(int j=0;j<i;j++)
				System.out.print(j+1);
			System.out.println();
		}
	}
}
Pattern 6:
p5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package Patternprogram;
 
 
class pattern20
{
	public static void main(String args[])
	{
		for(int i=1;i<=5;i++)
		{
 
			for(int j=5;j>i;j--)
 
				System.out.print(" ");
 
			for(int j=1;j<=2*i-1;j++)
 
				System.out.print(i);
 
			System.out.println();
		}
	}
}
Pattern 7:
p6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package Patternprogram;
 
 
 
class pattern21
{
	public static void main(String args[])
	{
		for(int i=1;i<=5;i++)
		{
 
			for(int j=5;j>i;j--)
 
				System.out.print(" ");
 
			for(int j=1;j<=2*i-1;j++)
 
				System.out.print(j);
 
			System.out.println();
		}
	}
}
Pattern 8:

p7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Patternprogram;
 
 
class pattern31
{
	public static void main(String arg[])
	{
		int n=5,ev=1,od=3,c1=3,c2=7;
 
		for(int i=0;i<n;i++)
		{
			int ep=ev,op=od;
 
			for(int j=0;j<=i;j++)
			{
				if(i%2==0)
					System.out.print(" "+ep++);
				else
					System.out.print(" "+op--);
			}
 
			System.out.println();
 
			if(i%2==0)
			{
				ev+=c1;
				c1+=4;
			}
 
			else
			{
				od+=c2;
				c2+=4;
			}
		}
	}
}
Pattern 9:
p8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package Patternprogram;
 
 
class pattern96
{
	public static void main(String args[])
	{
		int s=1,d=5;
		for(int i=5;i>0;i--)
		{
 
			for(int j=0;j<i;j++)
				System.out.print("*");
 
			for(int j=s;j>1;j--)
				System.out.print("  ");
 
			for(int k=d;k>=1;k--)
				System.out.print("*");
 
		System.out.println();
		s++;
		d--;
		}
	}
}

2 thoughts on “Interview Pattern Program in java

Leave a Reply

Your email address will not be published. Required fields are marked *