// Load required classes
import java.util.Scanner;
import java.io.File;

public class Exercise{ public static void main(String[] args) throws Exception{ // Scanner variable Scanner reader;

// If an argument is present,
// we are reading from a file
// specified in args[0]
if(args.length > 0){
  reader = new Scanner(new File(args[0]));
// If no argument, read from System.in
}else{
  reader = new Scanner(System.in);
}

<mark>/* -=-=-=-=- MORE CODE GOES HERE -=-=-=-=- */</mark>

} }

Skeleton

int m = reader.nextInt();
int n = reader.nextInt();

if(m > 0 && n > 0){

}else{ System.out.println(“Error - Invalid Input!"); }

Handle Input

int m = reader.nextInt();
int n = reader.nextInt();

if(m > 0 && n > 0){ int[][] array = new int[m][n];

}else{ System.out.println(“Error - Invalid Input!"); }

Create 2D Array

int m = reader.nextInt();
int n = reader.nextInt();

if(m > 0 && n > 0){ int[][] array = new int[m][n];

for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ array[i][j] = reader.nextInt(); } }

}else{ System.out.println(“Error - Invalid Input!"); }

Fill Array

int m = reader.nextInt();
int n = reader.nextInt();

if(m > 0 && n > 0){ int[][] array = new int[m][n];

for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ array[i][j] = reader.nextInt(); } }

for(int j = 0; j < n; j++){ for(int i = 0; i < m; i++){ System.out.print(array[i][j] + " “); } System.out.println(); }

}else{ System.out.println(“Error - Invalid Input!"); }

Transpose

"/js/highlight.pack.js"