Write a java program to print following pattern

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


import java.util.Scanner;
public class NumberPattern {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Size: ");
int n=sc.nextInt();

for (int i = 0; i < n; i++) {
int k=i+1;
for (int j = 0; j < n; j++) {
System.out.print(k+" ");
k+=n;
}
System.out.println();
}
}
}

Comments

Popular posts from this blog

program to calculate product of each column in matrix