Advertisement
Valleri

C# Basics Exam 25 July 2014 Evening

Jul 30th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class HouseWithAWindow {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.        
  9.         int roofHeight = input.nextInt();  
  10.         int houseWidth = roofHeight*2 - 1;
  11.         //top of the roof
  12.         System.out.printf("%1$s*%1$s\n", new String(new char[(houseWidth - 1) / 2]).replace('\0', '.'));
  13.        
  14.         // roof
  15.         for (int i = 0; i < roofHeight-1; i++) {
  16.             System.out.printf("%1$s*%2$s*%1$s\n", new String(new char[roofHeight-2 - i]).replace('\0', '.'),
  17.                                                 new String(new char[1 + (2*i)]).replace('\0', '.'));
  18.         }
  19.         //base of the roof
  20.         System.out.printf("%s\n", new String(new char[houseWidth]).replace('\0', '*'));
  21.        
  22.         //roof to window
  23.         for (int i = 0; i < roofHeight / 4; i++) {
  24.             System.out.printf("*%s*\n", new String(new char[houseWidth-2]).replace('\0', '.'));
  25.         }
  26.        
  27.         //window
  28.        
  29.         for (int i = 0; i < roofHeight / 2; i++) {
  30.             System.out.printf("*%1$s%2$s%1$s*\n", new String(new char[roofHeight/2]).replace('\0', '.'),
  31.                                                 new String(new char[roofHeight-3]).replace('\0', '*'));
  32.         }
  33.        
  34.         //window to floor
  35.         for (int i = 0; i < roofHeight / 4; i++) {
  36.             System.out.printf("*%s*\n", new String(new char[houseWidth-2]).replace('\0', '.'));
  37.         }
  38.        
  39.         // base of the house
  40.         System.out.printf("%s\n", new String(new char[houseWidth]).replace('\0', '*'));
  41.     }
  42.    
  43.    
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement