Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package matrixnotes;
- import java.util.Scanner;
- /**
- *
- * @author dinyangson
- */
- public class MatrixNotes {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- /*int[][] matrix = { {1, 2, 3},
- {4, 5, 6},
- {7, 8, 9} };
- for (int r = 0; r < matrix.length; r++)
- {
- for (int c = 0; c < matrix[0].length; c++)
- {
- System.out.println("Location:" + r + ", " + c + ", ");
- }
- System.out.println();
- }
- */
- Scanner scan = new Scanner(System.in);
- System.out.print("Rows? : ");
- int rows = scan.nextInt();
- System.out.print("Cols? : ");
- int cols = scan.nextInt();
- int[][] matrix = new int[rows][cols];
- for (int r = 0; r < matrix.length; r++)
- {
- for (int c = 0; c < matrix[0].length; c++)
- {
- System.out.println("Location" + r + ", " + c +": ");
- matrix[r][c] = scan.nextInt();
- }
- }
- System.out.println();
- matrixPrint(matrix);
- }
- public static void matrixPrint(int[][] matrix) {
- for (int r = 0; r < matrix.length; r++)
- {
- for (int c = 0; c < matrix[0].length; c++)
- {
- System.out.println(matrix[r][c] + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement