Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. public class TheGreatHourglass { public static void main(String[] args) {
  2.     int N = Integer.parseInt(args[0]);
  3. // Input an integer using command line arguments.
  4. // Accept all integer >= 3 printStar((2 * N) - 1);
  5. // Trivial
  6. nextLine();
  7. for (int i = 1; i < N - 1; i++)
  8. { /* ......... Start i = 1 * * i = 1 -> 1sp, 1*, 5sp, 1*, 1sp * * i = 2 -> 2sp, 1*, 3sp, 1*, 2sp * * i = 3 -> 3sp, 1*, 1sp, 1*, 3sp . Note: Last spaces in all lines is optional . . . . . . ......... */
  9.     printSpace(i);
  10. } printStar();
  11. printSpace(2 * (N - i) - 3);
  12. printStar();
  13. nextLine();
  14. } printSpace(N - 1);
  15. // Trivial
  16. printStar();
  17. nextLine();
  18. for (int i = N - 2; i >= 1; i--) { /* ......... . . . . . . . Start i = 5-2 = 3. * * i = 3 -> 3sp, 1*, 1sp, 1*, 3sp * * i = 2 -> 2sp, 1*, 3sp, 1*, 2sp * * i = 1 -> 1sp, 1*, 5sp, 1*, 1sp ......... Note: Last spaces in all lines is optional. */
  19.     printSpace(i);
  20. }
  21. printStar();
  22. printSpace(2 * (N - i) - 3);
  23. printStar();
  24. nextLine(); }
  25. printStar((2 * N) - 1);
  26. // Trivial
  27. nextLine(); }
  28. // Template Function
  29. // Makes it easier to understand.
  30. private static void printSpace(int amount)
  31. { for (int i = 0; i < amount; i++) printSpace(); }
  32. private static void printSpace() { System.out.print(" "); }
  33. private static void printStar(int amount) {
  34. for (int i = 0; i < amount; i++) printStar(); }
  35. private static void printStar() { System.out.print("*"); }
  36. private static void nextLine() { System.out.println(); } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement