Write a java program to print following pattern:-
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
import java.util.Scanner;
public class CountPattern31 {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter Size : ");
int n=sc.nextInt();
int k=1;
for(int i=1;i<=n;i++) {
int l=k+i-1;
for(int j=1;j<=i;j++) {
if (i%2 != 0) {
System.out.print(k+" ");
}
else {
System.out.print(l+" ");
}
k++;
l--;
}
System.out.println();
}
}
}
Comments
Post a Comment