Advertisement
dimipan80

C#Exams 3. New House (on Java Code)

Aug 22nd, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _3_NewHouse {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner scan = new Scanner(System.in);
  8.         int width = scan.nextInt();
  9.  
  10.         printTheRoofOfTheHouse(width);
  11.  
  12.         printTheFloorOfTheHouse(width);
  13.     }
  14.  
  15.     private static void printTheRoofOfTheHouse(int size) {
  16.         int hyphens = size / 2;
  17.         int asterisks = 1;
  18.         String hyphenSequence;
  19.         String asteriskSequence;
  20.         for (int row = 0; row <= size / 2; row++) {
  21.             hyphenSequence = newString('-', hyphens);
  22.             asteriskSequence = newString('*', asterisks);
  23.             System.out.printf("%1$s%2$s%1$s\n", hyphenSequence,
  24.                     asteriskSequence);
  25.             hyphens--;
  26.             asterisks += 2;
  27.         }
  28.     }
  29.  
  30.     private static void printTheFloorOfTheHouse(int size) {
  31.         // TODO Auto-generated method stub
  32.         String asteriskSequence = newString('*', size - 2);
  33.         for (int row = 0; row < size; row++) {
  34.             System.out.printf("|%s|\n", asteriskSequence);
  35.         }
  36.     }
  37.  
  38.     private static String newString(char ch, int size) {
  39.         StringBuilder sb = new StringBuilder();
  40.         for (int i = 0; i < size; i++) {
  41.             sb.append(ch);
  42.         }
  43.  
  44.         return sb.toString();
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement