Advertisement
skipter

House - Drawing with Loops / Java Basics

Apr 18th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 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.         if (n % 2 == 0) {
  9.              for (int i = 0; i < (n + 1) / 2 ; i++) {            // OK!
  10.                                                                  // OK!
  11.                 System.out.println(repeatStr("-", ((n / 2) - 1) - i)
  12.                         + repeatStr("*", 2 + (i * 2))
  13.                         + repeatStr("-", ((n / 2) - 1) - i));
  14.                 }
  15.                                                                  // OK1
  16.             for (int j = 0; j < n / 2 ; j++) {
  17.                 System.out.println("|" + repeatStr("*", n - 2) + "|");
  18.             }
  19.         }
  20.         if (!(n % 2 == 0)) {
  21.             for (int i = 0; i < (n + 1) / 2; i++) {
  22.                 System.out.println(repeatStr("-", (n / 2) - i) + repeatStr("*", 1 + (i * 2)) + repeatStr("-", (n / 2)- i));
  23.             }
  24.             for (int i = 0; i < n / 2; i++) {
  25.                 System.out.println("|" + repeatStr("*", n - 2) + "|");
  26.             }
  27.         }
  28.     }
  29.    public static String repeatStr(String repeatText, int counter) {
  30.         String text = "";
  31.        for (int i = 0; i < counter ; i++) {
  32.            text += repeatText;
  33.        }
  34.        return text;
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement