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 console = new Scanner(System.in);
- int n = Integer.parseInt(console.nextLine());
- int leftRightLines = (n - 1) / 2;
- if (n == 1) {
- System.out.println("*");
- }
- if (n == 2) {
- System.out.println("**");
- }
- if (n % 2 != 0 && n > 1) {
- System.out.println(method("-", (n - 1) / 2) + "*" + method("-", (n - 1) / 2));
- for (int i = 1; i <= (n - 1) / 2; i++) {
- System.out.println(method("-", leftRightLines - i) + "*" + method("-", i) + method("-", i - 1) +
- "*" + method("-", leftRightLines - i));
- }
- for (int i = 1; i <= (n - 1) / 2 - 1; i++) {
- System.out.println(method("-", i) + "*" + method("-", (n - 4) - (2 * (i - 1))) + "*" + method("-", i));
- }
- System.out.println(method("-", (n - 1) / 2) + "*" + method("-", (n - 1) / 2));
- }
- if (n % 2 == 0 && n > 2) {
- System.out.println(method("-", (n - 1) / 2) + "**" + method("-", (n - 1) / 2));
- for (int i = 1; i <= (n - 1) / 2; i++) {
- System.out.println(method("-", leftRightLines - i) + "*" + method("-", i) + method("-", i) +
- "*" + method("-", leftRightLines - i));
- }
- for (int i = 1; i <= (n - 1) / 2 - 1; i++) {
- System.out.println(method("-", i) + "*" + method("-", (n - 4) - (2 * (i - 1))) + "*" + method("-", i));
- }
- System.out.println(method("-", (n - 1) / 2) + "**" + method("-", (n - 1) / 2));
- }
- }
- public static String method(String text, int count) {
- String output = "";
- for (int i = 0; i < count; i++) {
- output = output + text;
- }
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment