Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Hourglass Java

public class hello {
  

  public static void main(String[] args) {
    System.out.printf("|""""""""""|
");
    for (int i=1; i<5; i++) {
        //* print leading spaces
        for (int j=0; j<i; j++) {
          System.out.printf(" ");
        }
        //* print single backslash
        System.out.printf("");
        //*print colons (8 for i=1 line, 6 for i = 2, ...)
        for (int j=0; j<10-2*i; j++) {
          System.out.printf(":");
        }
        //* print single forward slash and new line
        System.out.printf("/
");
    }
    //* print middle line
    System.out.printf("     ||     
");
    for (int i=1; i<5; i++) {
        //* print leading spaces ()
        for (int j=0; j<5-i; j++) {
          System.out.printf(" ");
        }
        //* print single backslash
        System.out.printf("/");
        //*print colons (8 for second line, 6 for third, ...)
        for (int j=0; j<2*i; j++) {
          System.out.printf(":");
        }
        //* print single forward slash and newline
        System.out.printf("
");
    }
    
    System.out.printf("|""""""""""|
");
  }
}
 
PREVIOUS NEXT
Tagged: #Hourglass #Java
ADD COMMENT
Topic
Name
3+2 =