write a program to print the following pattern-
1) 54321
4321
321
21
1
2) 1234567
12345
123
1
3) 12345
22345
33345
44445
55555
4) *
*#
*#*
*#*#
*#*#*
Answers
Answered by
5
1).
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
System.out.print(j);
}
System.out.println();
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
System.out.print(j);
}
System.out.println();
Ashvi16:
there are three more parts
Answered by
8
Here are the codes:
_____________________________________________________________
QUESTION 1:
public class Pattern_1
{
public static void main(String[] args)
{
int i,j;
for (i=5;i>0;i--)
{
for (j=i;j>0;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}
___________________________________________________________
QUESTION 2:
public class Pattern_2
{
public static void main(String args[])
{
int i,j;
for(i=7;0<i;i-=2)
{
for (j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
____________________________________________________________
QUESTION 3:
public class Pattern_3
{
public static void main(String args[])
{
int i,j,k,a=2;
for(i=1;i<6;i++)
{
for (j=1;j<=i;j++)
{
System.out.print(i);
}
for (k=a;k<6;k++)
{
System.out.print(k);
}
System.out.println();
a=a+1;
}
}
}
_____________________________________________________________
QUESTION 4:
public class Pattern_4
{
public static void main(String[] args)
{
int i,j,f;
for (i=1;i<6;i++)
{
f=1;
for (j=1;j<=i;j++)
{
System.out.print(((f%2)==0)? "#":"*");
f++;
}
System.out.println();
}
}
}
_____________________________________________________________
QUESTION 1:
public class Pattern_1
{
public static void main(String[] args)
{
int i,j;
for (i=5;i>0;i--)
{
for (j=i;j>0;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}
___________________________________________________________
QUESTION 2:
public class Pattern_2
{
public static void main(String args[])
{
int i,j;
for(i=7;0<i;i-=2)
{
for (j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}
____________________________________________________________
QUESTION 3:
public class Pattern_3
{
public static void main(String args[])
{
int i,j,k,a=2;
for(i=1;i<6;i++)
{
for (j=1;j<=i;j++)
{
System.out.print(i);
}
for (k=a;k<6;k++)
{
System.out.print(k);
}
System.out.println();
a=a+1;
}
}
}
_____________________________________________________________
QUESTION 4:
public class Pattern_4
{
public static void main(String[] args)
{
int i,j,f;
for (i=1;i<6;i++)
{
f=1;
for (j=1;j<=i;j++)
{
System.out.print(((f%2)==0)? "#":"*");
f++;
}
System.out.println();
}
}
}
Similar questions