myrdok123

06. Building

Jun 22nd, 2024
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Building_06 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int floors = Integer.parseInt(scanner.nextLine());
  10.         int rooms = Integer.parseInt(scanner.nextLine());
  11.  
  12.         //обикаляме през всеки етаж -> започваме от последния и приключваме на 1-вия етаж
  13.         for (int i = floors; i >= 1 ; i--) {
  14.  
  15.             //обикаляме през стаите -> започваме от нулевата стая и приключваме в последната - 1
  16.             for (int j = 0; j < rooms; j++) {
  17.                 //ако се намираме на последния етаж -> L + floor + room ->
  18.                 if (i == floors){
  19.                     System.out.printf("L%d%d ", i, j);
  20.                 } else if ( i % 2 == 0) {
  21.                     System.out.printf("O%d%d ", i, j);
  22.                 }else {
  23.                     System.out.printf("A%d%d ", i, j);
  24.                 }
  25.  
  26.             }
  27.  
  28.             System.out.println();
  29.  
  30.            
  31.         }
  32.  
  33.  
  34.  
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment