SHARE
TWEET

Untitled

a guest May 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top