Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Hourglass {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print("Enter size: ");
- int size = scanner.nextInt();
- System.out.print("Enter character: ");
- char character = scanner.next().charAt(0);
- for (int i = -size; i <= size; i++) {
- for (int j = 0; j < size - Math.abs(i); j++) {
- if (i != 0) {
- System.out.print(" ");
- }
- }
- for (int j = 0; j < Math.abs(2 * i); j++) {
- System.out.print(character);
- }
- if (i != 0) {
- System.out.println("");
- }
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement