Advertisement
KeepCoding

Diamond2

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