Advertisement
Guest User

House

a guest
Mar 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class House {
  4.     public static void main(String[] args) {
  5.                 Scanner console = new Scanner(System.in);
  6.                 int n = Integer.parseInt(console.nextLine());
  7.                 int stars = 0;
  8.  
  9.  
  10.                 if (n % 2 == 0) {
  11.                     stars = 2;
  12.                 } else {
  13.                     stars = 1;
  14.                 }
  15.                 int lines = (n - stars) / 2;
  16.  
  17.                 //top
  18.                 for (int i = 0; i < lines; i++) {
  19.                     System.out.print("-");
  20.                 }
  21.                 for (int i = 0; i < stars; i++) {
  22.                     System.out.print("*");
  23.                 }
  24.                 for (int i = 0; i < lines; i++) {
  25.                     System.out.print("-");
  26.                 }
  27.                 System.out.println();
  28.  
  29.                 //center
  30.                 for (int i = 1; i < (n + 1) / 2; i++) {
  31.                     stars = stars + 2;
  32.                     lines = lines - 1;
  33.                     //left lines
  34.                     for (int j = 0; j < lines; j++) {
  35.                         System.out.print("-");
  36.                     }
  37.                     for (int j = 0; j < stars; j++) {
  38.                         System.out.print("*");
  39.                     }
  40.  
  41.                     //right lines
  42.                     for (int j = 0; j < lines; j++) {
  43.                         System.out.print("-");
  44.                     }
  45.                     System.out.println();
  46.  
  47.                 }
  48.                 //bottom
  49.                 for (int i = 0; i <= n / 2 - 1; i++) {
  50.                     System.out.print("|");
  51.                     for (int j = 0; j < n - 2; j++) {
  52.                         System.out.print("*");
  53.                     }
  54.                     System.out.print("|");
  55.                     System.out.println();
  56.                 }
  57.             }
  58.  
  59.  
  60.             private static String repeat(String string, int count) {
  61.                 String output = "";
  62.  
  63.                 for (int i = 0; i < count; i++) {
  64.                     output += string;
  65.                 }
  66.  
  67.                 return output;
  68.             }
  69.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement