Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _3_NewHouse {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- int width = scan.nextInt();
- printTheRoofOfTheHouse(width);
- printTheFloorOfTheHouse(width);
- }
- private static void printTheRoofOfTheHouse(int size) {
- int hyphens = size / 2;
- int asterisks = 1;
- String hyphenSequence;
- String asteriskSequence;
- for (int row = 0; row <= size / 2; row++) {
- hyphenSequence = newString('-', hyphens);
- asteriskSequence = newString('*', asterisks);
- System.out.printf("%1$s%2$s%1$s\n", hyphenSequence,
- asteriskSequence);
- hyphens--;
- asterisks += 2;
- }
- }
- private static void printTheFloorOfTheHouse(int size) {
- // TODO Auto-generated method stub
- String asteriskSequence = newString('*', size - 2);
- for (int row = 0; row < size; row++) {
- System.out.printf("|%s|\n", asteriskSequence);
- }
- }
- private static String newString(char ch, int size) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < size; i++) {
- sb.append(ch);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement