Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.6 kB
61
Indexable
Never
import java.util.Scanner;

public class Main {
    // Метод для печати символа N раз (в 1 строку)
    public static void drawCharacter(char character, int times) {
        for (int i = 1; i <= times; i++) {
            System.out.print(character);
        }
    }

    public static void drawLine(int offsetFromStart, int s, boolean oneStar) {
        drawCharacter('|', offsetFromStart);
        if (!oneStar) {
            drawCharacter('*', 1);
            drawCharacter('-', s - offsetFromStart);
            drawCharacter('*', 1);
        } else {
            drawCharacter('*', 1);
        }
        drawCharacter('|', offsetFromStart);
        System.out.println();
    }

    public static void drawPicture(int s) {
        int i;
        for (i = 0; i < s - 2 - i; i++) {
            boolean drawOneStar;
            if (s % 2 == 0) {
                drawOneStar = false;
            } else {
                drawOneStar = (s - 2 - i * 2 < 1);
            }
            drawLine(i, s - 2 - i, drawOneStar);
        }
        if (s % 2 == 0) {
            drawLine(i, s - 2 - i, false);
        }
        for (; i >= 0; i--) {
            boolean drawOneStar;
            if (s % 2 == 0) {
                drawOneStar = false;
            } else {
                drawOneStar = (s - 2 - i * 2 < 1);
            }
            drawLine(i, s - 2 - i, drawOneStar);
        }
    }

    public static void main(String[] args) {
        System.out.print("Введите s: ");
        Scanner scanner = new Scanner(System.in);
        int s = scanner.nextInt();
        drawPicture(s);
    }
}