Advertisement
skipter

SunGlasses - Drawing with Loops / Java Basics

Apr 18th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.  
  5.         Scanner input = new Scanner(System.in);
  6.         int n = Integer.parseInt(input.nextLine());
  7.  
  8.         System.out.println(repeatStr("*", n * 2) + repeatStr(" ", n) + repeatStr("*", n * 2));
  9.         for (int col = 0; col < n - 3; col++) {
  10.             if (col == (n - 1) / 2 - 1) {
  11.                 System.out.println("*" + repeatStr("/", (n * 2) - 2) + "*" + repeatStr("|", n) + "*" + repeatStr("/", (n * 2) - 2) + "*");
  12.             }
  13.             System.out.println("*" + repeatStr("/", (n * 2) - 2) + "*" + repeatStr(" ", n) + "*" + repeatStr("/", (n * 2) - 2) + "*");
  14.         }
  15.         if (n <= 3) {
  16.             System.out.println("*" + repeatStr("/", (n * 2) - 2) + "*" + repeatStr("|", n) + "*" + repeatStr("/", (n * 2) - 2) + "*");
  17.         }
  18.         System.out.println(repeatStr("*", n * 2) + repeatStr(" ", n) + repeatStr("*", n * 2));
  19.  
  20.     }
  21.    public static String repeatStr(String repeatText, int counter) {
  22.         String text = "";
  23.        for (int i = 0; i < counter ; i++) {
  24.            text += repeatText;
  25.        }
  26.        return text;
  27.    }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement