velikova_olya

Crown

Mar 8th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package DrawingWithLoopsExams;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Crown {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. int width = (2 * n) - 1;
  12. int height = (n / 2) + 4;
  13.  
  14. //firstLine
  15. System.out.println("@" + repeatStr(" ", n - 2) + "@" + repeatStr(" ", n - 2) + "@");
  16.  
  17. //secondLine
  18. System.out.println("**" + repeatStr(" ", (width - 5) / 2) + "*" + repeatStr(" ", (width - 5) / 2) + "**");
  19.  
  20. //body
  21. int spaces = (width - 9) / 2;
  22. for (int i = 0; i < height - 6; i++) {
  23. String star = repeatStr("*", 1);
  24. String pointsLeftRight = repeatStr(".", i + 1);
  25. String pointsMiddle = repeatStr(".", 1 + 2 * i);
  26. System.out.println(star + pointsLeftRight + star + repeatStr(" ", spaces) + star + pointsMiddle
  27. + star + repeatStr(" ", spaces) + star + pointsLeftRight + star);
  28. spaces -= 2;
  29. }
  30.  
  31. //nextRow
  32. System.out.println("*" + repeatStr(".", (n - 1) / 2) + "*" + repeatStr(".", n - 3) + "*"
  33. + repeatStr(".", (n - 1) / 2) + "*");
  34.  
  35. //lastRowWithPoints
  36. System.out.println("*" + repeatStr(".", n / 2) + repeatStr("*", (width - n - 3)/2) + "."
  37. + repeatStr("*", (width - n - 3)/2) + repeatStr(".", n / 2) + "*");
  38.  
  39. //lastTwoRows
  40. System.out.println(repeatStr("*", width));
  41. System.out.println(repeatStr("*", width));
  42.  
  43. }
  44.  
  45. static String repeatStr(String strToRepeat, int count) {
  46. String text = "";
  47. for (int i = 0; i < count; i++) {
  48. text = text + strToRepeat;
  49. }
  50. return text;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment