Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class House {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- boolean isEven = n % 2 == 0;
- int roof = -1;
- if (isEven) {
- roof = n / 2;
- } else {
- roof = n / 2 + 1;
- }
- for (int row = 0; row < roof; row++) {
- int dashes = -1;
- int asterisk = -1;
- if (isEven) {
- dashes = n / 2 - 1;
- asterisk = 2;
- } else {
- dashes = n / 2;
- asterisk = 1;
- }
- System.out.print(repeatStr("-", dashes - row));
- System.out.print(repeatStr("*", asterisk + 2 * row));
- System.out.println(repeatStr("-", dashes - row));
- }
- for (int row = 0; row < n - roof; row++) {
- System.out.print("|");
- System.out.print(repeatStr("*", n - 2));
- System.out.println("|");
- }
- }
- static String repeatStr(String text, int count) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < count; i++) {
- sb.append(text);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment