Advertisement
veronikaaa86

Diamond

Oct 16th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Diamond1 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int stars = 1;
  10.         int dashesOut = (n-1)/2;
  11.         int dashesIn = n-4;
  12.  
  13.  
  14.         if (n%2==0){
  15.             for (int row = 0; row < n/2; row++) {
  16.                 System.out.println(repeatString("-", dashesOut) +
  17.                         "*" +
  18.                         repeatString("-", 2 * row) +
  19.                         "*" +
  20.                         repeatString("-", dashesOut));
  21.                 dashesOut--;
  22.             }
  23.             dashesOut = 1;
  24.             for (int row = 0; row < (n/2)-1; row++) {
  25.                 System.out.println(repeatString("-", dashesOut) +
  26.                         "*" +
  27.                         repeatString("-", dashesIn) +
  28.                         "*" +
  29.                         repeatString("-", dashesOut));
  30.                 dashesIn -= 2;
  31.                 dashesOut ++;
  32.  
  33.             }
  34.  
  35.         } else {
  36.             int starsTwo = 1;
  37.             if (n==1) {
  38.                 starsTwo = 0;
  39.             } else {
  40.                 System.out.println(repeatString("-", (n - 1) / 2) +
  41.                         repeatString("*", starsTwo) +
  42.                         repeatString("-", (n - 1) / 2));
  43.             }
  44.             for (int row = 0; row < n/2; row++) {
  45.                 System.out.println(repeatString("-", dashesOut-1) +
  46.                         "*" +
  47.                         repeatString("-", 2 * row + 1) +
  48.                         "*" +
  49.                         repeatString("-", dashesOut-1));
  50.                 dashesOut--;
  51.             }
  52.  
  53.             for (int row = 0; row < n/2-1; row++) {
  54.                 System.out.println(repeatString("-", row + 1) +
  55.                         "*" +
  56.                         repeatString("-", dashesIn) +
  57.                         "*" +
  58.                         repeatString("-", row + 1));
  59.                 dashesIn -= 2;
  60.                 dashesOut++;
  61.             }
  62.             System.out.println(repeatString("-", (n - 1)/2) +
  63.                     "*" +
  64.                     repeatString("-", (n - 1)/2) );
  65.         }
  66.     }
  67.     static String repeatString(String toRepeat, int count) {
  68.         String text = "";
  69.  
  70.         for (int i = 1; i <=count; i++) {
  71.             text = text + toRepeat;
  72.         }
  73.         return  text;
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement