Skip to content

Instantly share code, notes, and snippets.

@Hulzenga
Created March 22, 2014 21:16
Show Gist options
  • Save Hulzenga/9714499 to your computer and use it in GitHub Desktop.
Save Hulzenga/9714499 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class test {
public static double[][] get2DArrayInput(int array1DLength) {
Scanner stdin = new Scanner(System.in);
System.out.println("Please enter the data for the two-dimensional array.");
int rows = array1DLength;
System.out.print("Please enter the number of columns of the 2D array: ");
int columns = stdin.nextInt();
double[][] twoDArray = new double[rows][columns];
System.out.println("Please enter the array elements by rows: ");
for (int i = 0; i < array1DLength; i++) {
for (int j = 0; j < twoDArray[i].length; j++) {
twoDArray[i][j] = stdin.nextDouble();
}
}
return twoDArray;
}
public static void main(String[] args) {
double[][] test = get2DArrayInput(2);
for (int i = 0; i < test.length; i++) {
for (int j = 0; j < test[i].length; j++) {
System.out.print(String.valueOf(test[i][j]) + ", ");
}
System.out.println("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment