veronikaaa86

House 1

Feb 14th, 2018
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class House {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int stars = 1;
  10.  
  11.         if (n%2==0) {
  12.             stars = 2;
  13.         }
  14.  
  15.         int countRowRoof = (n+1)/2;
  16.         int dashes = (n-stars)/2;
  17.         for (int rowRoof = 0; rowRoof < countRowRoof; rowRoof++) {
  18.             System.out.print(repeatString("-", dashes));
  19.             System.out.print(repeatString("*", stars));
  20.             System.out.println(repeatString("-", dashes));
  21.             stars += 2;
  22.             dashes --;
  23.         }
  24.  
  25.         int countRowBody = n/2;
  26.         for (int rowBody = 0; rowBody < countRowBody; rowBody++) {
  27.             System.out.print(repeatString("|", 1));
  28.             System.out.print(repeatString("*", n-2));
  29.             System.out.println(repeatString("|",1));
  30.         }
  31.     }
  32.     static String repeatString(String toRepeat, int count) {
  33.         String text = "";
  34.  
  35.         for (int i = 1; i <=count; i++) {
  36.             text = text + toRepeat;
  37.         }
  38.         return  text;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment