borkins

Exam 17-Jul-2016 - 05. Diamond

May 17th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. /**
  2.  * Project: Exam_17_July_2016 - created by borkins on 2017-05-16.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _05_Diamond
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int n = Integer.parseInt(console.nextLine());
  14.        
  15.         for (int i = 0, j = n * 3; i < n; i++, j += 2)
  16.         {
  17.             printStr(".", (n - i));
  18.             printStr("*", 1);
  19.             printStr((i > 0) ? "." : "*", j - 2);
  20.             printStr("*", 1);
  21.             printStr(".", (n - i));
  22.             System.out.println();
  23.         }
  24.         printStr("*", (n * 5));
  25.         System.out.println();
  26.        
  27.         for (int i = 0, j = n * 5 - 4; i <= n * 2; i++, j -= 2)
  28.         {
  29.             printStr(".", (i + 1));
  30.             printStr("*", 1);
  31.             printStr((i < n * 2) ? "." : "*", j);
  32.             printStr("*", 1);
  33.             printStr(".", (i + 1));
  34.             System.out.println();
  35.         }
  36.     }
  37.    
  38.     public static void printStr(String str, int count)
  39.     {
  40.         for (int i = 0; i < count; i++) {
  41.             System.out.print(str);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment