Advertisement
iSpirited

Notes

Oct 4th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package matrixnotes;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11.  *
  12.  * @author dinyangson
  13.  */
  14. public class MatrixNotes {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args)
  20.     {
  21.  
  22.         /*int[][] matrix = { {1, 2, 3},
  23.          {4, 5, 6},
  24.          {7, 8, 9} };
  25.          for (int r = 0; r < matrix.length; r++)
  26.          {
  27.          for (int c = 0; c < matrix[0].length; c++)
  28.          {
  29.          System.out.println("Location:" + r + ",  " + c + ", ");  
  30.              
  31.          }
  32.          System.out.println();
  33.          }
  34.        
  35.          */
  36.         Scanner scan = new Scanner(System.in);
  37.         System.out.print("Rows? : ");
  38.         int rows = scan.nextInt();
  39.  
  40.         System.out.print("Cols? : ");
  41.         int cols = scan.nextInt();
  42.  
  43.         int[][] matrix = new int[rows][cols];
  44.         for (int r = 0; r < matrix.length; r++)
  45.         {
  46.             for (int c = 0; c < matrix[0].length; c++)
  47.             {    
  48.                 System.out.println("Location" + r + ", " + c +": ");
  49.                 matrix[r][c] = scan.nextInt();
  50.             }
  51.        
  52.            
  53.         }
  54.         System.out.println();
  55.         matrixPrint(matrix);
  56.     }  
  57.  
  58.    
  59.  
  60.     public static void matrixPrint(int[][] matrix) {
  61.         for (int r = 0; r < matrix.length; r++)
  62.         {
  63.             for (int c = 0; c < matrix[0].length; c++)
  64.             {
  65.                 System.out.println(matrix[r][c] + " ");
  66.  
  67.             }
  68.             System.out.println();
  69.         }
  70.  
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement