nikiman8888

House/Loops

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