how to write any pattern programs of java.
Answers
Answered by
4
Following is the basic java program to print pattern:
public class JavaProgram
{
public static void main(String args[])
{
int i, j;
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
public class JavaProgram
{
public static void main(String args[])
{
int i, j;
for(i=0; i<5; i++)
{
for(j=0; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}
Answered by
0
Answer:
class Pattern
{
public static void main()
{
for(int i=4;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
if(j%2==0)
System.out.print(i+" ");
else
System.out.print((i+1)+" ");
}
System.out.println();
}
for(int i=5,k=69;i>=0;i--,k--)
{
for(int j=1;j<=i;j++)
System.out.print((char)k+" ");
System.out.println();
}
}
}
Similar questions