Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Diamond {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- String inDashes, outDashes, border;
- for (int i = 0; i < n / 2 + (n % 2); i++) {
- outDashes = "-".repeat((n - 1) / 2 - i);
- border = "*";
- if (i == 0) {
- if (n % 2 == 0) {
- border = "**";
- }
- System.out.println(outDashes + border + outDashes);
- } else {
- inDashes = "-".repeat(i * 2);
- if (n % 2 == 1) {
- inDashes = "-".repeat(i * 2 - 1);
- }
- System.out.println(outDashes + border + inDashes + border + outDashes);
- }
- }
- for (int i = n / 2 - (1 + (n - 1) % 2); i >= 0; i--) {
- outDashes = "-".repeat((n - 1) / 2 - i);
- border = "*";
- if (i == 0) {
- if (n % 2 == 0) {
- border = "**";
- }
- System.out.println(outDashes + border + outDashes);
- } else {
- inDashes = "-".repeat(i * 2);
- if (n % 2 == 1) {
- inDashes = "-".repeat(i * 2 - 1);
- }
- System.out.println(outDashes + border + inDashes + border + outDashes);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement