Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HouseWithAWindow {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int roofHeight = input.nextInt();
- int houseWidth = roofHeight*2 - 1;
- //top of the roof
- System.out.printf("%1$s*%1$s\n", new String(new char[(houseWidth - 1) / 2]).replace('\0', '.'));
- // roof
- for (int i = 0; i < roofHeight-1; i++) {
- System.out.printf("%1$s*%2$s*%1$s\n", new String(new char[roofHeight-2 - i]).replace('\0', '.'),
- new String(new char[1 + (2*i)]).replace('\0', '.'));
- }
- //base of the roof
- System.out.printf("%s\n", new String(new char[houseWidth]).replace('\0', '*'));
- //roof to window
- for (int i = 0; i < roofHeight / 4; i++) {
- System.out.printf("*%s*\n", new String(new char[houseWidth-2]).replace('\0', '.'));
- }
- //window
- for (int i = 0; i < roofHeight / 2; i++) {
- System.out.printf("*%1$s%2$s%1$s*\n", new String(new char[roofHeight/2]).replace('\0', '.'),
- new String(new char[roofHeight-3]).replace('\0', '*'));
- }
- //window to floor
- for (int i = 0; i < roofHeight / 4; i++) {
- System.out.printf("*%s*\n", new String(new char[houseWidth-2]).replace('\0', '.'));
- }
- // base of the house
- System.out.printf("%s\n", new String(new char[houseWidth]).replace('\0', '*'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement