veronikaaa86

char matrix

Mar 13th, 2018
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package multidimencionalArrays;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.Arrays;
  7.  
  8. public class P04_TwoByTwoSquaresInMatrix {
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12.         String[] dim = reader.readLine().split("\\s+");
  13.  
  14.         int rows = Integer.parseInt(dim[0]);
  15.         int cols = Integer.parseInt(dim[1]);
  16.  
  17.         char[][] matrix = new char[rows][cols];
  18.  
  19.         for (int row = 0; row < rows; row++) {
  20.             char[] values = reader.readLine().toCharArray();
  21.             for (int col = 0; col < cols; col++) {
  22.                 if (row != ' ' && col != ' ') {
  23.                     matrix[row][col] = values[col];
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment