Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Pr09HouseNoMethod {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         int roof = n - n / 2;
  9.         int stars = (n % 2 == 0) ? 2 : 1;
  10.  
  11.         String baseLine = "|" + new String(new char[n - 2]).replace('\0', '*') + "|";
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             if (i < roof) {
  15.                 System.out.println(new String(new char[(n - stars) / 2]).replace('\0', '-') +
  16.                         new String(new char[stars]).replace("\0", "*") +
  17.                         new String(new char[(n - stars) / 2]).replace('\0', '-'));
  18.                 stars += 2;
  19.             } else {
  20.                 System.out.println(baseLine);
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement