Advertisement
StefanShivarov

Rhombus of Stars

Nov 1st, 2020
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4.  
  5.     public static void main(String[] args)   {
  6.  
  7.        Scanner scanner = new Scanner(System.in);
  8.  
  9.        int n = Integer.parseInt(scanner.nextLine());
  10.  
  11.        printUpperHalf(n);
  12.        printBottomHalf(n);
  13.     }
  14.  
  15.     private static void printSymbol(int count, String symbol){
  16.  
  17.         for(int s = 0; s < count; s++){
  18.  
  19.             System.out.print(symbol);
  20.         }
  21.     }
  22.  
  23.     private static void printUpperHalf(int count){
  24.  
  25.         int spacesAmount = count -1;
  26.         for(int r = 1; r <= count; r++){
  27.  
  28.             printSymbol(spacesAmount, " ");
  29.             printSymbol(r, "* ");
  30.             printSymbol(spacesAmount, " ");
  31.             spacesAmount--;
  32.             System.out.println();
  33.         }
  34.     }
  35.  
  36.     private static void printBottomHalf(int count){
  37.  
  38.         int spaceCounter = 1;
  39.         for(int r = count-1; r>0; r--){
  40.  
  41.             printSymbol(spaceCounter, " ");
  42.             printSymbol(r, "* ");
  43.             printSymbol(spaceCounter, " ");
  44.             spaceCounter++;
  45.             System.out.println();
  46.         }
  47.  
  48.     }
  49.  
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement