Advertisement
Guest User

Sunglases

a guest
Feb 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p08 {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.         int n = Integer.parseInt(console.nextLine());
  7.         //first row
  8.  
  9.         for (int row = 0; row < n; row++) {
  10.             //first part
  11.             if ((row == 0 || row == n - 1)) {
  12.                 System.out.print(repeatStr(2 * n, "*"));
  13.  
  14.             } else {
  15.                 System.out.print("*");
  16.                 System.out.print(repeatStr((n * 2) - 2, "/"));
  17.                 System.out.print("*");
  18.             }
  19.  
  20.             //Middle part
  21.             if (n % 2 == 0) {//even line
  22.                 if (row == n/2 -1){
  23.                     System.out.print(repeatStr(n ,"|"));
  24.                 }else {
  25.                     System.out.print(repeatStr(n ," "));
  26.                 }
  27.             }else {//odd line
  28.                 if (row == n /2){
  29.                     System.out.print(repeatStr(n ,"|"));
  30.                 }else {
  31.                     System.out.print(repeatStr(n ," "));
  32.                 }
  33.             }
  34.  
  35.             //last part
  36.             if ((row == 0 || row == n - 1)) {
  37.                 System.out.println(repeatStr(2 * n, "*"));
  38.  
  39.             } else {
  40.                 System.out.print("*");
  41.                 System.out.print(repeatStr((n * 2) - 2, "/"));
  42.                 System.out.println("*");
  43.             }
  44.         }
  45.     }
  46.     static String repeatStr (int count ,String text){
  47.         StringBuilder sb = new StringBuilder();
  48.         for (int i = 0; i < count; i++) {
  49.             sb.append(text);
  50.         }
  51.         return sb.toString();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement