wulev

DrawSandGlass

May 26th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class SandGlass {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = scanner.nextInt(); // height of the sand clock
  9.         int stars = n;
  10.         int dots = 1;
  11.        
  12.         for (int i = 0; i < n; i++) {
  13.             System.out.print('*');
  14.         }
  15.         System.out.println();
  16.        
  17.         while (true) {
  18.             DrawLine(stars, dots);
  19.             dots++;
  20.             stars -= 2;
  21.             if (stars == 1) {
  22.                 break;
  23.             }
  24.         }
  25.         stars = 5;
  26.         dots -= 2;
  27.         while (true) {
  28.             DrawLine(stars, dots);
  29.             stars += 2;
  30.             dots--;
  31.             if (dots == 0) {
  32.                 break;
  33.             }
  34.         }
  35.        
  36.         for (int i = 0; i < n; i++) {
  37.             System.out.print('*');
  38.         }
  39.        
  40.     }
  41.  
  42.     private static void DrawLine(int stars, int dots) {
  43.         for (int i = 0; i < dots; i++) {
  44.             System.out.print('.');
  45.         }
  46.         for (int i = 0; i < stars - 2; i++) {
  47.             System.out.print('*');
  48.         }
  49.         for (int i = 0; i < dots; i++) {
  50.             System.out.print('.');
  51.         }
  52.         System.out.println();
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment