martinvalchev

NumberTable

Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumberTable {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.             for (int row = 0; row < n; row++) {
  9.                 for (int col = 0; col < n; col++) {
  10.                    int num = row + col + 1;
  11.                     if (num > n){
  12.                        num = 2*n - num;
  13.                 }
  14.                 System.out.print(num + " ");
  15.             }
  16.                 System.out.println();
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment