Advertisement
16112

Курсова Работа 2 - 1.5 Брадва

Mar 27th, 2019
101
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 Edno_Pet {
  4.  
  5.     static String repeatStr(char s, int n) {
  6.         StringBuilder builder = new StringBuilder();
  7.         for (int i = 0; i < n; i++) {
  8.             builder.append(s);
  9.         }
  10.         return builder.toString();
  11.     }
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner sc = new Scanner(System.in);
  15.         int num = Integer.parseInt(sc.nextLine());
  16.         int num2 = num / 2;
  17.  
  18.         for (int i = 0; i < num; i++) {
  19.             System.out.printf("%s*%s*%s", repeatStr('-', 3 * num), repeatStr('-', i),
  20.                     repeatStr('-', (2 * num - 2 - i)));
  21.             System.out.println();
  22.         }
  23.  
  24.         for (int i = 0; i < num2; i++) {
  25.             System.out.printf("%s*%s*%s", repeatStr('*', 3 * num), repeatStr('-', num - 1), repeatStr('-', (num - 1)));
  26.             System.out.println();
  27.         }
  28.  
  29.         for (int i = 0; i < num2; i++) {
  30.             if (i != (num2 - 1)) {
  31.                 System.out.printf("%s*%s*%s", repeatStr('-', 3 * num - i), repeatStr('-', num - 1 + 2 * i),
  32.                         repeatStr('-', (num - 1 - i)));
  33.                 System.out.println();
  34.             } else {
  35.                 System.out.printf("%s*%s*%s", repeatStr('-', 3 * num - i), repeatStr('*', num - 1 + 2 * i),
  36.                         repeatStr('-', (num - 1 - i)));
  37.                 System.out.println();
  38.  
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement