Advertisement
coderrohan14

LoopingQues3.java

Jun 27th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Solution {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7. int spaces = n/2;
  8. for(int i=1;i<=(n/2)+1;i++){
  9. int stars = (2*i)-1;
  10. for(int j=1;j<=spaces;j++){
  11. System.out.print(" ");
  12. }
  13. spaces--;
  14. for(int j=1;j<=stars;j++){
  15. System.out.print("*");
  16. }
  17. System.out.println();
  18. }
  19. spaces = 1;
  20. for(int i=(n/2);i>=1;i--){
  21. int stars = (2*i)-1;
  22. for(int j=1;j<=spaces;j++){
  23. System.out.print(" ");
  24. }
  25. spaces++;
  26. for(int j=1;j<=stars;j++){
  27. System.out.print("*");
  28. }
  29. System.out.println();
  30. }
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement