0% found this document useful (0 votes)
17 views10 pages

Pattern Part 1

Uploaded by

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

Pattern Part 1

Uploaded by

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

Pattern

Incase on increment i.e ++ then control will be <=e.g: for(i=1; i<=10; i++)
Incase on decrement i.e -- then control will be >=e.g: for(i=10; i>=1; i--)
Horizontal print started from left side vertical print start up to down
e.g→

Ptrn1) Write a program to display the given pattern


1 2 3 ****
2 4 6 ****
3 6 9 ****

Hints:-Table of 1, 2 & 3 upto 3


1 x1 1x2 1x3 ****
2x1 2x2 2x3 ****
3x1 3x2 3x3 ****

int i, j;
for(i=1; i<=3;i++)
{
for(j=1; j<=3; j++)
System.out.print(i*j+" ");
System.out.println("****");
}

Ptrn2) Write a program to display the given pattern


1
24
369

1x1
2x1 2x2
3x1 3x2 3x3

int i, j;
for(i=1; i<=3;i++)
{
for(j=1; j<=i; j++)
System.out.print(i*j+" ");
System.out.println( );
}
Ptrn3) Write a program to display the following pattern
123
369
5 10 15
Hints:-Table of 1, 3 & 5 upto 3
1x1 1x2 1x3
3x1 3x2 3x3
5x1 5x2 5x3
inti, j;
for(i=1; i<=5;i++)
{
for(j=1; j<=3; j++)
{
if(i%2==0)
continue;// to skip the even no.
System.out.print(i*j+" ");
}
System.out.println();
}

Ptrn4) Write a program to display the given pattern


1
12
123
1234
12345

int a, b;
for(a=1; a<=5; a++)
{
for(b=1; b<=a; b++)
System.out.print(b+” “);
System.out.println( );
}
Ptrn5) Write a program to display the given pattern
54321
4321
321
21
1

inti, j;
for(i=5; i>=1;i--)
{
for(j=i; j>=1; j--)
System.out.print(j+" ");
System.out.println();
}

Ptrn6) Write a program to display the given pattern


12345
2345
345
45
5

inti,j;
for (i=1; i<=5; i++)
{
for (j = i; j <= 5; j++)
System.out.print(j+" ");
System.out.println();
}

Ptrn7) Write a program to display the given pattern


1
21
321
4321
54321

inti,j;
for (i = 1; i<= 5; i++)
{
for (j = i; j >= 1; j--)
System.out.print(j+" ");
System.out.println();
}
Ptrn8) Write a program to display the given pattern
9
79
579
3579
13579

inti,j;
for(i=9; i>=1; i-=2)
{
for(j=i; j<=9; j+=2)
System.out.print(j+" ");
System.out.println( );
}

Ptrn9) Write a program to display the given pattern


12345
1234
123
12
1

inti,j;
for (i = 5; i>= 1; i--)
{
for (j = 1; j <= i; j++)
System.out.print(j+" ");
System.out.println();
}

Ptrn10) Write a program to display the given pattern


13579
1357
135
13
1

inti,j;
for (i=9; i>=1; i-=2)
{
for (j = 1; j <= i; j+=2)
System.out.print(j+" ");
System.out.println();
}
Ptrn 11) Write a program to display the given pattern
1234567
12345
123
1

inti, j;
for(i=7; i>=1;i-=2)
{
for(j=1; j<=i; j++)
System.out.print(j+" ");
System.out.println();
}

Ptrn 12) Write a program to display the given pattern


54321
5432
543
54
5

inti,j;
for (i = 1; i<= 5; i++)
{
for (j = 5; j >= i; j--)
System.out.print(j+" ");
System.out.println();
}

Ptrn 13) Write a program to display the given pattern


5
54
543
5432
54321

inti,j;
for (i=5; i>=1; i--)
{
for (j = 5; j >= i; j--)
System.out.print(j+" ");
System.out.println();
}
Ptrn 14) Write a program to display the given pattern
97531
9753
975
97
9

inti, j;
for(i=1; i<=9;i+=2)
{
for(j=9; j>=i; j-=2)
System.out.print(j+" ");
System.out.println();
}

Q) WAP to pring the pattern


1
31
531
7531
97531

// WAP to pring the pattern


public class p1
{
public static void main(String args[])
{
int i, j;
for(i=1; i<=9;i+=2)
{
for(j=i; j>=1; j-=2)
System.out.print(j+" ");
System.out.println();
}
}
}

Ptrn 15) Write a program to display the given pattern


*
**
***
****
*****
inti,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
System.out.print("*"+" ");
System.out.println( );
}
Ptrn 16) Write a program to display the given pattern
1 1
10 2
101 3
1010 4
10101 5
inti,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
if(j%2==0)
System.out.print(0+" ");
else
System.out.print(1+" ");
}
System.out.println( );
}

Ptrn17) Write a program to display the given pattern


*
*#
*#*
*#*#
*#*#*
inti,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
{
if(j%2==0)
System.out.print("#"+" ");
else
System.out.print("*"+" ");
}
System.out.println( );
}
Ptrn18) Write a program to display the given pattern
11111
22222
33333
44444
55555
inti,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=5; j++)
System.out.print(i+" ");
System.out.println( );
}

Ptrn19) Write a program to display the given pattern


55555
44444
33333
22222
11111

inti,j;
for(i=5; i>=1; i--)
{
for(j=1; j<=5; j++)
System.out.print(i+" ");
System.out.println( );
}

Ptrn20) Write a program to display the given pattern


99999
77777
55555
33333
11111

inti,j;
for(i=9; i>=1; i-=2)
{
for(j=1; j<=5; j++)
System.out.print(i+" ");
System.out.println( );
}
Ptrn 21) Write a program to display the given pattern
1
22
333
4444
55555
inti,j;
for(i=1; i<=5; i++)
{
for(j=1; j<=i; j++)
System.out.print(i+" ");
System.out.println( );
}
Ptrn 22) Write a program to display the given pattern
666666
55555
4444
333
22
1
inti,j;
for(i=6; i>=1; i--)
{
for(j=i; j>=1; j--)
System.out.print(i+" ");
System.out.println( );
}

You might also like