Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- printUpperHalf(n);
- printBottomHalf(n);
- }
- private static void printSymbol(int count, String symbol){
- for(int s = 0; s < count; s++){
- System.out.print(symbol);
- }
- }
- private static void printUpperHalf(int count){
- int spacesAmount = count -1;
- for(int r = 1; r <= count; r++){
- printSymbol(spacesAmount, " ");
- printSymbol(r, "* ");
- printSymbol(spacesAmount, " ");
- spacesAmount--;
- System.out.println();
- }
- }
- private static void printBottomHalf(int count){
- int spaceCounter = 1;
- for(int r = count-1; r>0; r--){
- printSymbol(spaceCounter, " ");
- printSymbol(r, "* ");
- printSymbol(spaceCounter, " ");
- spaceCounter++;
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement