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());
- if (n % 2 == 0) {
- for (int i = 0; i < n - 1; i++) {
- if (i <= n / 2 - 1) {
- String first = repeatStr("-", (n / 2 - 1) - i) + "*" + repeatStr("-", i * 2) + "*" + repeatStr("-", n / 2 - 1 - i);
- System.out.println(first);
- } else {
- String first = repeatStr("-", i - n / 2 + 1) + "*" + repeatStr("-", (n - 2 - i) * 2) + "*" + repeatStr("-", i - n / 2 + 1);
- System.out.println(first);
- }
- }
- } else {
- String second1 = repeatStr("-", n / 2) + "*" + repeatStr("-", n / 2);
- System.out.println(second1);
- for (int i = 1; i <= n - 2; i++) {
- if (i <= n / 2) {
- String second = repeatStr("-", n / 2 - i) + "*" + repeatStr("-", (i*2) - 1) + "*" + repeatStr("-", n / 2 - i);
- System.out.println(second);
- }else {
- String second = repeatStr("-", i - n / 2 ) + "*" + repeatStr("-", (n - 2 - i) * 2 +1) + "*" + repeatStr("-", i - n / 2);
- System.out.println(second);
- }
- }
- if (n != 1)
- System.out.println(second1);
- }
- }
- static String repeatStr(String text, int count) {
- StringBuilder result = new StringBuilder();
- for (int i = 0; i < count; i++) {
- result.append(text);
- }
- return result.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement