Advertisement
Boyan5

oop1

Jun 24th, 2021
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class zad1 {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         int i,j;
  6.         System.out.print("Enter rows for the array : ");
  7.         int rows = scanner.nextInt();
  8.         System.out.print("Enter columns for the array: ");
  9.         int cols = scanner.nextInt();
  10.         System.out.println("Enter " + (rows * cols) + " array elements: ");
  11.         int[][] matrix = new int[rows][cols];
  12.         for ( i = 0; i < rows; i++) {
  13.             for ( j = 0; j < cols; j++) {
  14.                 matrix[i][j] = scanner.nextInt();
  15.             }
  16.         }
  17.                 System.out.println("The 2D array is :");
  18.                 for (i = 0; i < rows; i++) {
  19.                     for (j = 0; j < cols; j++) {
  20.                         System.out.print(matrix[i][j] + "  ");
  21.                     }
  22.                     System.out.println();
  23.                 }
  24.             }
  25.         }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement