Advertisement
Guest User

Hourglass

a guest
Feb 26th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Hourglass {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. System.out.print("Enter size: ");
  9. int size = scanner.nextInt();
  10. System.out.print("Enter character: ");
  11. char character = scanner.next().charAt(0);
  12.  
  13. for (int i = -size; i <= size; i++) {
  14. for (int j = 0; j < size - Math.abs(i); j++) {
  15. if (i != 0) {
  16. System.out.print(" ");
  17. }
  18. }
  19. for (int j = 0; j < Math.abs(2 * i); j++) {
  20. System.out.print(character);
  21. }
  22. if (i != 0) {
  23. System.out.println("");
  24. }
  25. }
  26.  
  27. scanner.close();
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement