fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. /* Christopher Isherwood
  9.   CSC 115
  10.   9/30/2014
  11.   Hour Glass Program
  12.   Homework #1
  13.   This program will print a image of a hour glass depending on the size of the constant
  14.  
  15.   Used ideone.com to check code due to an "jGRASP wedge2 error: command "javac" not found." with jGRASP
  16.   Had to use "public class Main" for the website. Would normally use "public class HourGlass"
  17. */
  18.  
  19. public class Main
  20. {
  21. public static final int SIZE = 17;
  22. public static void main(String[] args) {
  23. end();
  24. top();
  25. vertical();
  26. bottom();
  27. end();
  28. }
  29.  
  30. // Produces ends of the Hour Glass
  31. public static void end()
  32. {
  33. System.out.print("|");
  34. int i;
  35. for (i=1; i <=SIZE*2+2; i++)
  36. {
  37. System.out.print("\"");
  38. }
  39. System.out.println("|");
  40. }
  41.  
  42. // This produces the top half of the hourglass figure
  43. public static void top()
  44. {
  45. for (int j=1; j <=SIZE; j++)
  46. {
  47. int i;
  48. for (i=1; i <=(j*SIZE)/SIZE; i++){
  49. System.out.print(" ");
  50. }
  51. System.out.print("\\");
  52. int k;
  53. for (k=j; k<=SIZE; k++){
  54. System.out.print("::");
  55. }
  56. System.out.println("/");
  57. }
  58. }
  59.  
  60. // This produces the bottom half of the hourglass figure
  61. public static void bottom()
  62. {
  63. for (int j=1; j <=SIZE; j++)
  64. {
  65. int i;
  66. for (i=1; i <=(SIZE+1)-j; i++){
  67. System.out.print(" ");
  68. }
  69. System.out.print("/");
  70. int k;
  71. for (k=1; k<=j; k++){
  72. System.out.print("::");
  73. }
  74. System.out.println("\\");
  75. }
  76. }
  77. // Produces the middle bars
  78. public static void vertical()
  79. {
  80. int i;
  81. for (i=1; i <=SIZE+1; i++)
  82. {
  83. System.out.print(" ");
  84. }
  85. System.out.println("||");
  86. }
  87. }
Success #stdin #stdout 0.14s 47184KB
stdin
Standard input is empty
stdout
|""""""""""""""""""""""""""""""""""""|
 \::::::::::::::::::::::::::::::::::/
  \::::::::::::::::::::::::::::::::/
   \::::::::::::::::::::::::::::::/
    \::::::::::::::::::::::::::::/
     \::::::::::::::::::::::::::/
      \::::::::::::::::::::::::/
       \::::::::::::::::::::::/
        \::::::::::::::::::::/
         \::::::::::::::::::/
          \::::::::::::::::/
           \::::::::::::::/
            \::::::::::::/
             \::::::::::/
              \::::::::/
               \::::::/
                \::::/
                 \::/
                  ||
                 /::\
                /::::\
               /::::::\
              /::::::::\
             /::::::::::\
            /::::::::::::\
           /::::::::::::::\
          /::::::::::::::::\
         /::::::::::::::::::\
        /::::::::::::::::::::\
       /::::::::::::::::::::::\
      /::::::::::::::::::::::::\
     /::::::::::::::::::::::::::\
    /::::::::::::::::::::::::::::\
   /::::::::::::::::::::::::::::::\
  /::::::::::::::::::::::::::::::::\
 /::::::::::::::::::::::::::::::::::\
|""""""""""""""""""""""""""""""""""""|