Write two separate programs to generate the following patterns 11111
11112
11123
11234
12345
54321
43212
32123
21234
12345
Answers
Answered by
1
Question:-
To print the patterns
Pattern 1:
11112
11123
11234
12345
Code:-
import java.util.*;
class Code
{
public static void main (String ar [])
{
int c=2;
for (int i=1;i<=5;i++)
{
for (int j=5;j>i;j--)
{
System.out.print("1");
}
for(j=2;j<=c;j++)
{
System.out.print(j);
}
c++;
System.out.println();
}
}
}
_______________
Pattern 1:
54321
43212
32123
21234
12345
Code:-
import java.util.*;
class Code
{
public static void main (String ar [])
{
c=1;
for(int i=5;i>=1;i--)
{
for (int j=i;i>1;j--)
{
System.out.print(j);
}
for (int j=1;j<=c;j++)
{
System.out.print(j);
}
c++;
System.out.println();
}
}
Similar questions