TheBulgarianWolf

Rhombus printed with stars

Feb 21st, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Main {
  3.   public static void main(String[] args) {
  4.     Scanner sc = new Scanner(System.in);
  5.     System.out.print("Enter the number of stars in the middle of the rhombus: ");
  6.     int numberOfStars = Integer.parseInt(sc.nextLine());
  7.     //the for cycle for smaller to bigger part of the figure
  8.     for(int row = 1; row<= numberOfStars;row++){
  9.       for(int col = 1;col <= numberOfStars - row;col++){
  10.         System.out.print(" ");
  11.       }
  12.       System.out.print("*");
  13.       for(int col = 1; col<row;col++){
  14.         System.out.print(" *");
  15.       }
  16.       System.out.println();
  17.     }
  18.  
  19.     //the for cycle for bigger to the smaller part of the figure
  20.     int bonus = 1;
  21.     for(int row = numberOfStars - bonus; row >= 1;row--){
  22.       for(int col = 1;col <= numberOfStars - row;col++){
  23.         System.out.print(" ");
  24.       }
  25.       System.out.print("*");
  26.       for(int col = 1; col<row;col++){
  27.         System.out.print(" *");
  28.       }
  29.       System.out.println();
  30.       bonus++;
  31.     }
  32.   }
  33. }
Add Comment
Please, Sign In to add comment