Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DrawingWithLoopsExams;
- import java.util.Scanner;
- public class Crown {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int width = (2 * n) - 1;
- int height = (n / 2) + 4;
- //firstLine
- System.out.println("@" + repeatStr(" ", n - 2) + "@" + repeatStr(" ", n - 2) + "@");
- //secondLine
- System.out.println("**" + repeatStr(" ", (width - 5) / 2) + "*" + repeatStr(" ", (width - 5) / 2) + "**");
- //body
- int spaces = (width - 9) / 2;
- for (int i = 0; i < height - 6; i++) {
- String star = repeatStr("*", 1);
- String pointsLeftRight = repeatStr(".", i + 1);
- String pointsMiddle = repeatStr(".", 1 + 2 * i);
- System.out.println(star + pointsLeftRight + star + repeatStr(" ", spaces) + star + pointsMiddle
- + star + repeatStr(" ", spaces) + star + pointsLeftRight + star);
- spaces -= 2;
- }
- //nextRow
- System.out.println("*" + repeatStr(".", (n - 1) / 2) + "*" + repeatStr(".", n - 3) + "*"
- + repeatStr(".", (n - 1) / 2) + "*");
- //lastRowWithPoints
- System.out.println("*" + repeatStr(".", n / 2) + repeatStr("*", (width - n - 3)/2) + "."
- + repeatStr("*", (width - n - 3)/2) + repeatStr(".", n / 2) + "*");
- //lastTwoRows
- System.out.println(repeatStr("*", width));
- System.out.println(repeatStr("*", width));
- }
- static String repeatStr(String strToRepeat, int count) {
- String text = "";
- for (int i = 0; i < count; i++) {
- text = text + strToRepeat;
- }
- return text;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment