Advertisement
Spocoman

06. Building (solutions with or not ternary operator)

Aug 30th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Building {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int floorCount = Integer.parseInt(scanner.nextLine());
  7.         int flatFloorCount = Integer.parseInt(scanner.nextLine());
  8.         String appendix;
  9.  
  10.         for (int floor = floorCount; floor > 0; floor--) {
  11.             if (floor == floorCount) {
  12.                 appendix = "L";
  13.             } else if (floor % 2 == 1) {
  14.                 appendix = "A";
  15.             } else {
  16.                 appendix = "O";
  17.             }
  18.  
  19.             for (int flatFloor = 0; flatFloor < flatFloorCount; flatFloor++) {
  20.                 System.out.printf("%s%d%d ", appendix, floor, flatFloor);
  21.             }
  22.             System.out.println();
  23.         }
  24.     }
  25. }
  26.  
  27. ИЛИ:
  28.  
  29. import java.util.Scanner;
  30.  
  31. public class Building {
  32.     public static void main(String[] args) {
  33.         Scanner scanner = new Scanner(System.in);
  34.         int floorCount = Integer.parseInt(scanner.nextLine());
  35.         int flatFloorCount = Integer.parseInt(scanner.nextLine());
  36.         String appendix;
  37.  
  38.         for (int floor = floorCount; floor > 0; floor--) {
  39.             appendix = floor == floorCount ? "L" : floor % 2 == 1 ? "A" : "O";
  40.             for (int flatFloor = 0; flatFloor < flatFloorCount; flatFloor++) {
  41.                 System.out.printf("%s%d%d ", appendix, floor, flatFloor);
  42.             }
  43.             System.out.println();
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement