Created
October 4, 2018 20:13
-
-
Save gdusbabek/cbe60ef57bd3f9e0f02c8e590955b10c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hourglass { | |
public static void main(String args[]) { | |
// top | |
for (int i = 0; i < 5; i++) { | |
// print header | |
if (i == 0) { | |
System.out.println("|\"\"\"\"\"\"\"\"\"|"); | |
} else { | |
// print spaces | |
for (int j = 0; j < i; j++) { | |
System.out.print(" "); | |
} | |
// print slash | |
System.out.print("\\"); | |
// print colons 9-2*i | |
for (int j = 0; j < 9-2*i; j++) { | |
System.out.print(":"); | |
} | |
// print slash | |
System.out.print("/"); | |
// print newline | |
System.out.println(); | |
} | |
} | |
// bottom | |
for (int i = 5; i > 0; i--) { | |
// maybe print footer | |
if (i == 1) { | |
System.out.println("|\"\"\"\"\"\"\"\"\"|"); | |
} else { | |
for (int j = 0; j < i-1; j++) { | |
System.out.print(" "); | |
} | |
// print slash | |
System.out.print("/"); | |
// print colons 11-2*i | |
for (int j = 0; j < 11-2*i; j++) { | |
System.out.print(":"); | |
} | |
// print slash | |
System.out.print("\\"); | |
// print newline | |
System.out.println(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment