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