Advertisement
Guest User

Untitled

a guest
May 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TestTask2New {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         if (n % 2 == 0) {
  9.             String firstRow = "/" + repeatStr("^", n / 2) + "\\" + repeatStr("_", n - 4)
  10.                     + "/" + repeatStr("^", n / 2) + "\\";
  11.             System.out.println(firstRow);
  12.         } else {
  13.             System.out.println("/" + repeatStr("^", n / 2) + "\\" + repeatStr("_", n - 3)
  14.                     + "/" + repeatStr("^", n / 2) + "\\");
  15.         }
  16.         for (int i = 0; i < n - 3; i++) {
  17.             String middleRows = "|" + repeatStr(" ", 2 * n - 2) + "|";
  18.             System.out.println(middleRows);
  19.  
  20.         }
  21.         if (n % 2 == 0) {
  22.             String rowBeforeLast = "|" + repeatStr(" ", n / 2 + 1)
  23.                     + repeatStr("_", n - 4) + repeatStr(" ", n / 2 + 1) + "|";
  24.             System.out.println(rowBeforeLast);
  25.         } else {
  26.             System.out.println("|" + repeatStr(" ", n / 2 + 1)
  27.                     + repeatStr("_", n - 3) + repeatStr(" ", n / 2 + 1) + "|");
  28.         }
  29.         if (n % 2 == 0) {
  30.             String lastRow = "\\" + repeatStr("_", n / 2) + "/"
  31.                     + repeatStr(" ", n - 4) + "\\" + repeatStr("_", n / 2)
  32.                     + "/";
  33.             System.out.println(lastRow);
  34.         }else {
  35.             System.out.println("\\" + repeatStr("_", n / 2) + "/"
  36.                     + repeatStr(" ", n - 3) + "\\" + repeatStr("_", n / 2)
  37.                     + "/");
  38.         }
  39.     }
  40.  
  41.     static String repeatStr(String strToRepeat, int count) {
  42.         String text = "";
  43.         for (int i = 0; i < count; i++) {
  44.             text += strToRepeat;
  45.  
  46.         }
  47.         return text;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement