skipter icon

SunGlasses - Drawing with Loops / Java Basics

skipter | PRO | 04/18/17 06:20:46 PM UTC | 0 ⭐ | 330 👁️ | Never ⏰ | []
Java |

1.15 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) + repeatStr(" ", n) + repeatStr("*", n * 2));
        for (int col = 0; col < n - 3; col++) {
            if (col == (n - 1) / 2 - 1) {
                System.out.println("*" + repeatStr("/", (n * 2) - 2) + "*" + repeatStr("|", n) + "*" + repeatStr("/", (n * 2) - 2) + "*");
            }
            System.out.println("*" + repeatStr("/", (n * 2) - 2) + "*" + repeatStr(" ", n) + "*" + repeatStr("/", (n * 2) - 2) + "*");
        }
        if (n <= 3) {
            System.out.println("*" + repeatStr("/", (n * 2) - 2) + "*" + repeatStr("|", n) + "*" + repeatStr("/", (n * 2) - 2) + "*");
        }
        System.out.println(repeatStr("*", n * 2) + repeatStr(" ", n) + repeatStr("*", n * 2));
 
    }
   public static String repeatStr(String repeatText, int counter) {
        String text = "";
       for (int i = 0; i < counter ; i++) {
           text += repeatText;
       }
       return text;
   }
}

Comments