Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package ow222ea_assign2;
  2. import java.util.Scanner;
  3. public class Diamonds {
  4. public static void main(String[] args) {
  5. Scanner input = new Scanner(System.in);
  6. System.out.print("Give a postive number: ");
  7. int number = input.nextInt();
  8. int startandfinishspaces = number -1;
  9. int firstlinestar = 1;
  10. int maxstars = number*2 - 1;
  11. for(int i=0;i<number;i++){
  12. for(int j=0;j<startandfinishspaces;j++) {
  13. System.out.print(" ");
  14. }
  15. for(int k=0;k<firstlinestar;k++) {
  16. System.out.print("*");
  17. }
  18. startandfinishspaces--;
  19. firstlinestar+=2;
  20. System.out.println(" ");
  21. }
  22. for(int i=-1;i>=1;i--){
  23. for(int j=-1;j<startandfinishspaces+2;j++) {
  24. System.out.print(" ");
  25. }
  26. for(int k=1;k>=maxstars-4;k++) {
  27. System.out.print("*");
  28. }
  29. startandfinishspaces--;
  30. maxstars-=2;
  31. System.out.println(" ");
  32.  
  33. input.close();
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement