Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class zad1 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int i,j;
- System.out.print("Enter rows for the array : ");
- int rows = scanner.nextInt();
- System.out.print("Enter columns for the array: ");
- int cols = scanner.nextInt();
- System.out.println("Enter " + (rows * cols) + " array elements: ");
- int[][] matrix = new int[rows][cols];
- for ( i = 0; i < rows; i++) {
- for ( j = 0; j < cols; j++) {
- matrix[i][j] = scanner.nextInt();
- }
- }
- System.out.println("The 2D array is :");
- for (i = 0; i < rows; i++) {
- for (j = 0; j < cols; j++) {
- System.out.print(matrix[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement