Advertisement
Guest User

Diamond

a guest
Feb 20th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Jo on 2/20/2017.
  5.  */
  6. public class Diamond {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int diamondSize = Integer.parseInt(scanner.nextLine());
  10.  
  11.         if (diamondSize % 2 != 0) {
  12.             for (int i = 0; i <= diamondSize / 2; i++) {
  13.                 if (i != 0) {
  14.                     System.out.println(draw("-", diamondSize / 2 - i) + draw("*", 1)
  15.                             + draw("-", 2 * i - 1) + draw("*", 1) + draw("-", diamondSize / 2 - i));
  16.                 } else {
  17.                     System.out.println(draw("-", diamondSize / 2 - i) + draw("*", 1)
  18.                             + draw("-", 2 * i - 1) + draw("-", diamondSize / 2 - i));
  19.                 }
  20.             }
  21.             for (int i = (diamondSize - 1) / 2; i > 0 / 2; i--) {
  22.                 if (i != 1) {
  23.                     System.out.println(draw("-", diamondSize / 2 - i + 1) + draw("*", 1)
  24.                             + draw("-", 2 * i - 3) + draw("*", 1) + draw("-", diamondSize / 2 - i + 1));
  25.                 } else {
  26.                     System.out.println(draw("-", diamondSize / 2 - i + 1) + draw("*", 1)
  27.                             + draw("-", 2 * i - 3) + draw("-", diamondSize / 2 - i + 1));
  28.                 }
  29.             }
  30.         } else {
  31.             for (int i = 0; i <= diamondSize / 2 - 1; i++) {
  32.                 System.out.println(draw("-", diamondSize / 2 - 1 - i) + draw("*", 1)
  33.                         + draw("-", 2 * i) + draw("*", 1) + draw("-", diamondSize / 2 - 1 - i));
  34.             }
  35.             for (int i = (diamondSize - 1) / 2; i > 0; i--) {
  36.                 System.out.println(draw("-", diamondSize / 2 - i) + draw("*", 1)
  37.                         + draw("-", 2 * (i - 1)) + draw("*", 1) + draw("-", diamondSize / 2 - i));
  38.             }
  39.  
  40.         }
  41.  
  42.     }
  43.  
  44.     public static String draw(String str, int count) {
  45.         StringBuilder sb = new StringBuilder();
  46.  
  47.         for (int i = 0; i < count; i++) {
  48.             sb.append(str);
  49.         }
  50.         return sb.toString();
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement