Advertisement
paykova

House

Oct 30th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class p09_House {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = Integer.parseInt(scanner.nextLine());
  7.  
  8. for (int i = 0; i < (n +1) / 2; i++) {
  9. if (n % 2 == 0) {
  10. String roof = repeatStr("-", (n - 2) / 2 - i)
  11. + repeatStr("*", n - (n - 2) + i + i)
  12. + repeatStr("-", (n - 2) / 2 - i);
  13. System.out.println(roof);
  14. } else if (n%2 != 0){
  15. String roof1 = repeatStr("-", (n - 1) / 2 - i)
  16. + repeatStr("*", 1 + i + i)
  17. + repeatStr("-", (n - 1) / 2 - i);
  18. System.out.println(roof1);
  19. }
  20. }
  21. //String staticLine = repeatStr("*", n);
  22. // System.out.println(staticLine);
  23.  
  24. for (int i = 0; i <= n / 2 - 1; i++) {
  25.  
  26. String baseHouse = "|"
  27. + repeatStr("*", n - 2)
  28. + "|";
  29. System.out.println(baseHouse);
  30. }
  31. }
  32. static String repeatStr(String strToRepeat, int count) {
  33. String text = "";
  34. for (int i = 0; i < count; i++) {
  35. text += strToRepeat;
  36.  
  37. }
  38. return text;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement