Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package p05_Diamond;
- 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());
- String dots = repeatStr(".", n);
- System.out.println(dots + repeatStr("*", n * 3) + dots);
- int dotsCount = n * 3;
- int dotsCount2 = n * 5 - 4;
- for (int i = n; i > 1; i--) {
- System.out.println(repeatStr(".", i - 1) + "*" + repeatStr(".", dotsCount) + "*" + repeatStr(".", i - 1));
- dotsCount +=2;
- }
- System.out.println(repeatStr("*", n * 5));
- for (int i = 1; i <= n * 2; i++) {
- System.out.println(repeatStr(".", i) + "*" + repeatStr(".", dotsCount2) + "*" + repeatStr(".", i));
- dotsCount2 -=2;
- }
- System.out.println(repeatStr(".", n * 2 + 1) + repeatStr("*", n - 2) + repeatStr(".", n * 2 + 1));
- }
- static String repeatStr(String str, int count) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < count; i++) {
- sb.append(str);
- }
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement