Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class HollowDiamond {
  6. public static void main(String[] args) {
  7. Scanner input = new Scanner(System.in);
  8. System.out.print("Please enter a number : ");
  9. int n = input.nextInt();
  10. for (int row = 1; row <=n; row++) {
  11. for (int col = 1; col <=n-row; col++) {
  12. System.out.print(" ");
  13. }
  14. for (int col = 1; col <=row; col++) {
  15. if(col==row){
  16. System.out.print("*");
  17. }
  18. else{
  19. System.out.print(" ");
  20. }
  21.  
  22. }
  23. for (int col = 2; col <=row; col++) {
  24. if(row==col){
  25. System.out.print("*");
  26. }
  27. else{
  28. System.out.print(" ");
  29. }
  30. }
  31. System.out.println("");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement