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