Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SandGlass {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt(); // height of the sand clock
- int stars = n;
- int dots = 1;
- for (int i = 0; i < n; i++) {
- System.out.print('*');
- }
- System.out.println();
- while (true) {
- DrawLine(stars, dots);
- dots++;
- stars -= 2;
- if (stars == 1) {
- break;
- }
- }
- stars = 5;
- dots -= 2;
- while (true) {
- DrawLine(stars, dots);
- stars += 2;
- dots--;
- if (dots == 0) {
- break;
- }
- }
- for (int i = 0; i < n; i++) {
- System.out.print('*');
- }
- }
- private static void DrawLine(int stars, int dots) {
- for (int i = 0; i < dots; i++) {
- System.out.print('.');
- }
- for (int i = 0; i < stars - 2; i++) {
- System.out.print('*');
- }
- for (int i = 0; i < dots; i++) {
- System.out.print('.');
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment