Advertisement
deyanmalinov

1. Fill the Matrix

Mar 30th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String[] line = scan.nextLine().split(", ");
  9.         int  size = Integer.parseInt(line[0]);
  10.         String type = line[1];
  11.         int[][] matrix = new int[size][size];
  12.         int fill= 1;
  13.         for (int i = 0; i < size; i++) {
  14.             if (i%2==0){
  15.                 for (int j = 0; j < size; j++) {
  16.                     matrix[j][i] = fill++;
  17.                 }
  18.             }else {
  19.                 for (int j = matrix.length-1; j >= 0; j--) {
  20.                     matrix[j][i] = fill++;
  21.                 }
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement