Advertisement
Guest User

Untitled

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