예제 #1
0
파일: Transpose.java 프로젝트: mak619/CSE2
 public static void main(String[] args) { // define main method
   int width = -1; // declare width variable
   int height = -1; // declare height variable
   Scanner myScanner = new Scanner(System.in); // declare Scanner variable
   System.out.print("Enter the width of the matrix: "); // prompt user to enter input
   while (myScanner.hasNextInt() == false) { // checking if value is an integer or not
     System.out.print("Sorry, you did not enter an integer. Try again: "); // try again
     String junk = myScanner.next();
   }
   width = myScanner.nextInt(); // assign user's input to width
   while (width <= 0) { // if mon is a negative number
     System.out.print("Please only enter positive numbers. Try again: ");
     while (myScanner.hasNextInt() == false) { // checking if value is an integer or not
       System.out.print("Sorry, you did not enter an integer. Try again: ");
       String junk = myScanner.next();
     }
     width = myScanner.nextInt(); // final width value
   }
   System.out.print("Enter the height of the matrix: "); // prompt use to enter input
   while (myScanner.hasNextInt() == false) { // checking if value is an integer or not
     System.out.print("Sorry, you did not enter an integer. Try again: "); // try again
     String junk = myScanner.next();
   }
   height = myScanner.nextInt(); // assign user's input to width
   while (height <= 0) { // if mon is a negative number
     System.out.print("Please only enter positive numbers. Try again: ");
     while (myScanner.hasNextInt() == false) { // checking if value is an integer or not
       System.out.print("Sorry, you did not enter an integer. Try again: ");
       String junk = myScanner.next();
     }
     height = myScanner.nextInt(); // final width value
   }
   System.out.println("Matrix:");
   int[][] matrix =
       randomMatrix(width, height); // call randomMatrix and run it with width and height
   printMatrix(matrix); // call printMatrix and print the matrix
   int[][] transposedMatrix = transposeMatrix(matrix); // call transponseMatrix and run it
   System.out.println("Transposed matrix: ");
   printMatrix(transposedMatrix); // call printMatrix and print the transposed matrix
 } // end of main method
예제 #2
0
파일: Transpose.java 프로젝트: Ruben19/CSE2
 public static void main(String[] args) {
   Scanner myScanner = new Scanner(System.in); // declares the scanner
   System.out.print(" Enter Int for rows and Int for colums"); // prompts the user to input a int.
   int rows =
       myScanner
           .nextInt(); // creates variable called row and declares it as the first input value.
   int colums =
       myScanner
           .nextInt(); // creates varaible called colums declares it as the second input value.
   int[][] matrix; // creates 2d array called matrix
   int[][] newarray; // creates 2d array called new array.
   System.out.println(" ");
   randomMatrix(rows, colums); // calls method
   matrix = randomMatrix(rows, colums); // calls method
   printMatrix(matrix); // calls method
   transposeMatrix(matrix);
   newarray = transposeMatrix(matrix);
   System.out.println(matrix.length);
   System.out.println("");
   System.out.println("");
   printMatrix(newarray);
 }