Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner scan = new Scanner(System.in);
- System.out.print("How many rows? ");
- Integer rows = Integer.valueOf(scan.nextLine());
- System.out.print("How many columns?");
- Integer columns = Integer.valueOf(scan.nextLine());
- double two_d[][] = new double[rows][columns];
- int i, j;
- for (i = 0; i < rows; i++) {
- System.out.print("Enter " + columns + " numbers seperated by comma (" + (i + 1) + " row): ");
- String[] line = scan.nextLine().split(",");
- for (j = 0; j < columns; j++) {
- two_d[i][j] = Double.parseDouble(line[j]);
- }
- }
- for (i = 0; i < rows; i++) {
- for (j = 0; j < columns; j++) {
- System.out.print(two_d[i][j] + " ");
- }
- System.out.println();
- }
- scan.close();
- }
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("How many rows? ");
- int rows = Integer.valueOf(scan.nextLine());
- System.out.print("How many columns?");
- int columns = Integer.valueOf(scan.nextLine());
- double two_d[][] = new double[rows][columns];
- int i, j;
- for (i = 0; i < rows; i++) {
- System.out.print("Enter " + columns + " numbers seperated by comma (" + (i + 1) + " row): ");
- String[] line = scan.nextLine().split(",");
- double low = Double.MIN_VALUE;
- for (j = 0; j < columns; j++) {
- two_d[i][j] = Double.parseDouble(line[j]);
- if (two_d[i][j] < low) {
- System.out.println("Error you number is to small"); //Set an error message
- i--;
- }
- else
- low = two_d[i][j];
- }
- }
- for (i = 0; i < rows; i++) {
- for (j = 0; j < columns; j++) {
- System.out.print(two_d[i][j] + " ");
- }
- System.out.println();
- }
- scan.close();
- }
- }
Add Comment
Please, Sign In to add comment