Advertisement
borkins

Exam Jan-2016 - 09. Perfect Diamond

May 11th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. /**
  2.  * Project: Exam_101_January_2016 - created by borkins on 2017-05-03.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _09_PerfectDiamond
  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 = 1, l = 1; i <= n; i++, l += 2)
  16.         {
  17.             for (int j = i; j < n; j++) {
  18.                 System.out.print(" ");
  19.             }
  20.            
  21.             for (int k = 1; k <= l; k++) {
  22.                 System.out.print((k % 2 == 0) ? "-" : "*");
  23.             }
  24.             System.out.println();
  25.         }
  26.        
  27.         for (int i = 1, l = n * 2 - 3; i < n; i++, l -= 2)
  28.         {
  29.             for (int j = 1; j <= i; j++) {
  30.                 System.out.print(" ");
  31.             }
  32.            
  33.             for (int k = 1; k <= l; k++) {
  34.                 System.out.print((k % 2 == 0) ? "-" : "*");
  35.             }
  36.             System.out.println();
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement