TheBulgarianWolf

Table of Numbers

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