Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TheGreatHourglass { public static void main(String[] args) {
- int N = Integer.parseInt(args[0]);
- // Input an integer using command line arguments.
- // Accept all integer >= 3 printStar((2 * N) - 1);
- // Trivial
- nextLine();
- for (int i = 1; i < N - 1; i++)
- { /* ......... 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 . . . . . . ......... */
- printSpace(i);
- } printStar();
- printSpace(2 * (N - i) - 3);
- printStar();
- nextLine();
- } printSpace(N - 1);
- // Trivial
- printStar();
- nextLine();
- 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. */
- printSpace(i);
- }
- printStar();
- printSpace(2 * (N - i) - 3);
- printStar();
- nextLine(); }
- printStar((2 * N) - 1);
- // Trivial
- nextLine(); }
- // Template Function
- // Makes it easier to understand.
- private static void printSpace(int amount)
- { for (int i = 0; i < amount; i++) printSpace(); }
- private static void printSpace() { System.out.print(" "); }
- private static void printStar(int amount) {
- for (int i = 0; i < amount; i++) printStar(); }
- private static void printStar() { System.out.print("*"); }
- private static void nextLine() { System.out.println(); } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement