Ramya Chekuri
8 years ago

Write a java program to print the below pattern
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
21 20 19 18 17 16

Solution (By Examveda Team)

public class HelloWorld{
public static void main(String []args){
int k = 1;
int x=1;
for (int i = 1; i <= 10; i++)
{
if(i%2==0){
x=k+i-1;
for (int j = 1; j <= i; j++)
{
System.out.print(x+" ");
x--;
k++;
}
}
else{
x=k;
for (int j = 1; j <= i; j++)
{
System.out.print(x+" ");
x++;
k++;
}
}
System.out.println();
}
}
}


Miscellaneous mcq solution image

This Question Belongs to User Ask Question >> Miscellaneous

Join The Discussion

Comments (1)

  1. Rakesh Gautam
    Rakesh Gautam:
    8 years ago

    21 20 19 18 17 16

Related User Ask Questions