skipter icon

Hourglass - Drawing with Loops

skipter | PRO | 04/19/17 01:10:17 PM UTC | 0 ⭐ | 301 👁️ | Never ⏰ | []
Java |

1.27 KB

|

None

|

0 👍

/

0 👎

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
 
        int n = Integer.parseInt(input.nextLine());
 
        System.out.println(repeatStr("*", n * 2 + 1));
        System.out.println(".*" + repeatStr(" ", (n * 2 + 1) - 4) + "*.");
 
            for (int j = 0; j < n - 2; j++) {
                System.out.println(repeatStr(".", (2 + j)) + "*" + repeatStr("@",((n -j)*2) - 5)
                     + "*" + repeatStr(".", (2 + j)));
        }
        System.out.println(repeatStr(".", n) + "*" + repeatStr(".", n));
        System.out.println(repeatStr(".", n - 1) + "*@*" + repeatStr(".", n - 1));
        for (int i = 0; i < n - 3; i++) {
            System.out.println(repeatStr(".",(n - 2) - i ) + "*" + repeatStr(" ",1 + i)
                    + "@" + repeatStr(" ", 1 + i) + "*" + repeatStr(".", (n - 2) - i));
        }
        System.out.println(".*" + repeatStr("@",((n * 2) + 1) - 4 ) + "*.");
        System.out.println(repeatStr("*", n * 2 + 1));
 
 
    }
    public static String repeatStr(String repeatString, int counter) {
        String text = "";
        for (int i = 0; i < counter; i++) {
            text += repeatString;
        }
        return text;
    }
}

Comments