Advertisement
SUni2020

PerfectDiamond

Mar 28th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class PerfectDiamond {
  6. public static void main(String[] args) {
  7.  
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. int n = Integer.parseInt(scanner.nextLine());
  11.  
  12. for (int a = 1; a <= n; a++) {
  13. System.out.print(repeatStr(" ",n -a));
  14. System.out.print("*");
  15.  
  16. for (int b = 0;b < a - 1;b++){
  17. System.out.print("-*");
  18. }
  19. System.out.println();
  20. }
  21. for (int a = n -1; a >= 1; a--){
  22. System.out.print(repeatStr(" ",n -a));
  23. System.out.print("*");
  24.  
  25. for (int b = 1;b < a; b++){
  26. System.out.print("-*");
  27. }
  28. System.out.println();
  29. }
  30.  
  31.  
  32. }
  33. static String repeatStr(String strToRepeat,int count){
  34. String text ="";
  35.  
  36. for (int i = 0;i < count;i++){
  37. text = text + strToRepeat;
  38. }
  39. return text;
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement