@GeorgeGibby/

Matrix Fun

Java

No description

fork
loading
Files
  • Main.java
  • input.txt
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
import java.io.*;
class Main {
  
  public static void main(String[] args) throws IOException {
  int[][] mat;
  int rows;
  int cols;
  Scanner reader = new Scanner(new File("input.txt"));
  rows = reader.nextInt();
  cols = reader.nextInt();
  mat = new int[rows][cols];

  for(int row = 0; row < rows; row++)
  {
    for(int col = 0; col < cols; col++)
    {
      mat[row][col] = reader.nextInt();
    }
  }
  System.out.println("Your matrix: ");
  for(int row = 0; row < rows; row++)
  {
    for(int col = 0; col < cols; col++)
    {
      System.out.print(mat[row][col] + "\t");   
    }
    System.out.println();
  }
  }
}