Advertisement
Lyubohd

Building

Dec 13th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Building {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         int floors = Integer.parseInt(scan.nextLine()); // прочитаме броя на етажите
  7.         int rooms = Integer.parseInt(scan.nextLine()); // прочитаме броя на стаите за всеки етаж
  8.  
  9.         for (int floor = floors; floor >= 1; floor--) { // намаляващ for за всеки етаж, тъй като печатаме първо последният, а накрая 1ви
  10.             for (int room = 0; room < rooms; room++) { // for за всяка стая на всеки етаж
  11.                 if (floor == floors) { // ако етажа е последен
  12.                     System.out.print("L" + floor + room + " "); // печатаме L за голям апартамент
  13.                 } else if (floor % 2 == 0) { // ако етажа е четен
  14.                     System.out.print("O" + floor + room + " "); // печатаме O за офис
  15.                 } else {
  16.                     System.out.print("A" + floor + room + " "); // печатаме A за апартамент
  17.                 }
  18.             }
  19.             System.out.println(); // преместваме курсора на следващият ред, за да следващият етаж
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement