Advertisement
GabrielHr00

06. Building

Feb 8th, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package nestedLoops_Lab;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Building {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int floors = Integer.parseInt(scanner.nextLine());
  9.         int rooms = Integer.parseInt(scanner.nextLine());
  10.  
  11.         for (int i = floors; i >= 1; i--) {
  12.  
  13.             for (int j = 0; j < rooms; j++) {
  14.  
  15.                 if (i == floors) {
  16.                     System.out.printf("L%d%d ",i, j);
  17.                 }
  18.                 else if (i % 2 == 0) {
  19.                     // четен етаж
  20.                     System.out.printf("O%d%d ",i, j);
  21.                 }
  22.                 else {
  23.                     // нечетен етаж
  24.                     System.out.printf("A%d%d ",i, j);
  25.                 }
  26.             }
  27.             System.out.println();
  28.         }
  29.  
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement