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