KeepCoding

Arrow

Jan 15th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Arrow {
  4.     public static void main(String[] args) {
  5.         Scanner console = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(console.nextLine()); //nechetno chislo
  8.  
  9.         int pictureWidth = n * 2 - 1;
  10.         //first row:
  11.         System.out.print(returnStr(n / 2, "."));
  12.         System.out.print(returnStr(n, "#"));
  13.         System.out.println(returnStr(n / 2, "."));
  14.         //top half:
  15.         int topHalfHeight = n - 2;
  16.         for (int row = 0; row < topHalfHeight; row++) {
  17.             System.out.print(returnStr(n / 2, "."));
  18.             System.out.print("#");
  19.             System.out.print(returnStr(pictureWidth - n / 2 - n / 2 - 2, "."));
  20.             System.out.print("#");
  21.             System.out.println(returnStr(n / 2, "."));
  22.         }
  23.         //middle row:
  24.         System.out.print(returnStr(n / 2 + 1, "#"));
  25.         System.out.print(returnStr(pictureWidth - n / 2 - n / 2 - 2, "."));
  26.         System.out.println(returnStr(n / 2 + 1, "#"));
  27.         //bottom half:
  28.         int botHalfHeight = n - 1;
  29.         for (int row = 1; row <= botHalfHeight; row++) {
  30.             System.out.print(returnStr(row, "."));
  31.             System.out.print("#");
  32.             System.out.print(returnStr(pictureWidth - 2 - row * 2, "."));
  33.             if (row != botHalfHeight) {
  34.                 System.out.print("#");
  35.             }
  36.             System.out.println(returnStr(row, "."));
  37.         }
  38.         //main ends here
  39.     }
  40.  
  41.     static String returnStr (int count, String character) {
  42.         StringBuilder sb = new StringBuilder();
  43.         for (int i = 0; i < count; i++) {
  44.             sb.append(character);
  45.         }
  46.         return sb.toString();
  47.     }
  48.  
  49. }
Add Comment
Please, Sign In to add comment