Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pr08SunglassesNoMethod {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         String starsSection = new String(new char[2 * n]).replace('\0', '*');
  9.         String glassSection = "*" + new String(new char[2 * n - 2]).replace('\0', '/') + '*';
  10.         String middleEmptySection = new String(new char[n]).replace('\0', ' ');
  11.         String middleFrameSection = new String(new char[n]).replace('\0', '|');
  12.  
  13.         String headerFooterLine = starsSection + middleEmptySection + starsSection;
  14.         String frameLine = glassSection + middleFrameSection + glassSection;
  15.         String glassesLine = glassSection + middleEmptySection + glassSection;
  16.  
  17.         int frameN = n / 2 - ((n % 2 == 0) ? 1 : 0);
  18.  
  19.         for (int i = 0; i < n; i++) {
  20.             if (i == 0 || i == n - 1) {
  21.                 System.out.println(headerFooterLine);
  22.             } else if (i == frameN) {
  23.                 System.out.println(frameLine);
  24.             } else {
  25.                 System.out.println(glassesLine);
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement