-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamondPattern.java
More file actions
39 lines (39 loc) · 870 Bytes
/
DiamondPattern.java
File metadata and controls
39 lines (39 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
1. import java.util.Scanner;
2. public class DiamondPattern
3. {
4. public static void main(String args[])
5. {
6. int row, i, j, space = 1;
7. System.out.print("Enter the number of rows you want to print: ");
8. Scanner sc = new Scanner(System.in);
9. row = sc.nextInt();
10. space = row - 1;
11. for (j = 1; j<= row; j++)
12. {
13. for (i = 1; i<= space; i++)
14. {
15. System.out.print(" ");
16. }
17. space--;
18. for (i = 1; i <= 2 * j - 1; i++)
19. {
20. System.out.print("*");
21. }
22. System.out.println("");
23. }
24. space = 1;
25. for (j = 1; j<= row - 1; j++)
26. {
27. for (i = 1; i<= space; i++)
28. {
29. System.out.print(" ");
30. }
31. space++;
32. for (i = 1; i<= 2 * (row - j) - 1; i++)
33. {
34. System.out.print("*");
35. }
36. System.out.println("");
37. }
38. }
39. }