Advertisement
Spocoman

08. Sunglasses(with ternary operator)

Aug 31st, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Sunglasses {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         for (int i = 0; i < n; i++) {
  8.             for (int j = 0; j < n * 2; j++) {
  9.                 System.out.print((i != 0 && i != n - 1 && j != 0 && j != n * 2 - 1) ? '/' : '*');
  10.             }
  11.             for (int k = 0; k < n; k++) {
  12.                 System.out.print(((i == n / 2 && n % 2 == 1) || (i + 1 == n / 2 && n % 2 == 0)) ? '|' : ' ');
  13.             }
  14.             for (int j = 0; j < n * 2; j++) {
  15.                 System.out.print((i != 0 && i != n - 1 && j != 0 && j != n * 2 - 1) ? '/' : '*');
  16.             }
  17.             System.out.println();
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement