Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Project: Drawing_With_Loops - created by borkins on 2017-04-15
- */
- import java.util.Scanner;
- public class _10_Diamond
- {
- public static void main(String[] args)
- {
- Scanner console = new Scanner(System.in);
- int n = Integer.parseInt(console.nextLine()); // 0 <= n <= 63
- long[] arr = new long[(n > 1) ? (n - (n >> 1) - 1) : n];
- long mid = (1L << n - 1) + 1;
- long half = mid >> 1;
- long add = 2;
- for (int i = arr.length - 1; i >= 0; i--)
- {
- if (i == 0 && n % 2 != 0) {
- arr[i] = half;
- break;
- }
- arr[i] = half + add;
- half >>= 1;
- add <<= 1;
- }
- for (int i = 0; i < arr.length; i++) drawLine(arr[i], n);
- if (n > 1) {
- drawLine(mid, n);
- for (int i = arr.length - 1; i >= 0; i--) drawLine(arr[i], n);
- }
- }
- public static void drawLine(long num, int count)
- {
- long mask = 1L;
- for (int i = 0; i < count; i++) {
- System.out.print((num & mask) == 0 ? "-" : "*");
- mask <<= 1;
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment