Write a java program to print following pattern:-

1 2 3 4 5 
10 9 8 7 6 
11 12 13 14 15 
20 19 18 17 16 
21 22 23 24 25 


import java.util.Scanner;
public class CountPattern27 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Size: ");
int n=sc.nextInt();
int k=1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i%2 != 0) {
  System.out.print(k+" ");
} else {
System.out.print((-j+i*n+1)+" ");
}
k++;
}
System.out.println();
}
}
}

Comments

Popular posts from this blog