Advertisement
Vladkoheca

Garaj 2D array.java

Oct 22nd, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | Source Code | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scanner = new Scanner(System.in);
  8.         System.out.println("How many floors: ");
  9.         int parkingFloor = Integer.parseInt(scanner.nextLine());
  10.         System.out.println("How many spots: ");
  11.         int parkingSpots = Integer.parseInt(scanner.nextLine());
  12.  
  13.         String[][] cars = new String[parkingFloor][parkingSpots];
  14.         for (int i = 0; i < cars.length; i++) {
  15.             System.out.println();
  16.             for (int j = 0; j < cars[i].length; j++) {
  17.                 System.out.println("Car arrived, model: ");
  18.                 cars[i][j] = scanner.nextLine();
  19.             }
  20.             if (cars.length - i == 1) {
  21.                 break;
  22.             }
  23.             System.out.println("Премина на следващ етаж");
  24.         }
  25.         System.out.println(Arrays.deepToString(cars));
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement