Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem05_ChristmasSock {
  4. public static void main(String[] args) {
  5. Scanner console = new Scanner(System.in);
  6. int n = Integer.parseInt(console.nextLine());
  7. int height = 3 * n + 3;
  8.  
  9. System.out.printf("|%s|%n", repeatStr("-", 2 * n));
  10. System.out.printf("|%s|%n", repeatStr("*", 2 * n));
  11. System.out.printf("|%s|%n", repeatStr("-", 2 * n));
  12. for (int row = 0; row < n - 1; row++) {
  13. System.out.printf("|%s%s%s|%n", repeatStr("-", n - 1 - row), repeatStr("~", row * 2 + 2),
  14. repeatStr("-", n - 1 - row));
  15. }
  16. for (int row = n - 3; row >= 0; row--) {
  17. System.out.printf("|%s%s%s|%n", repeatStr("-", n - 1 - row), repeatStr("~", row * 2 + 2),
  18. repeatStr("-", n - 1 - row));
  19. }
  20. for (int row = 0; row < height - n * 2; row++) {
  21. if (row == n / 2 ) {
  22. System.out.printf("%s\\%sMERRY%s\\%n", repeatStr("-", row), repeatStr(".", n - 2),
  23. repeatStr(".", n - 2));
  24. } else if (row == n / 2 + 2) {
  25. System.out.printf("%s\\%sX-MAS%s\\%n", repeatStr("-", row), repeatStr(".", n - 2),
  26. repeatStr(".", n - 2));
  27. } else if (row == height - n * 2-1) {
  28. System.out.printf("%s\\%s)%n", repeatStr("-", row), repeatStr("_", n * 2 + 1));
  29.  
  30. } else {
  31. System.out.printf("%s\\%s\\%n", repeatStr("-", row), repeatStr(".", n * 2 + 1));
  32. }
  33.  
  34. }
  35.  
  36. }
  37.  
  38. public static String repeatStr(String text, int count) {
  39. String result = "";
  40. for (int i = 0; i < count; i++) {
  41. result += text;
  42. }
  43. return result;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement