Answers for "Hourglass Java"

0

Hourglass Java

public class hello {
  

  public static void main(String[] args) {
    System.out.printf("|\"\"\"\"\"\"\"\"\"\"|\n");
    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("/\n");
    }
    //* print middle line
    System.out.printf("     ||     \n");
    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("\\\n");
    }
    
    System.out.printf("|\"\"\"\"\"\"\"\"\"\"|\n");
  }
}
Posted by: Guest on October-09-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language