Advertisement
skipter

Rhombus of Stars - Drawing with Loops - Java

Apr 13th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         Scanner input = new Scanner(System.in);
  5.         int n = Integer.parseInt(input.nextLine());
  6.  
  7.         for (int stars = 1; stars <= n; stars++) {
  8.             for (int j = 0; j < n - stars; j++) {
  9.                 System.out.print(" ");
  10.             }
  11.             for (int i = 1; i <= stars ; i++) {
  12.                 System.out.print("* ");
  13.             }
  14.             System.out.println();
  15.         }
  16.  
  17.         for (int stars = n - 1; stars >= 1; stars--) {
  18.             for (int j = 0; j < n - stars; j++) {
  19.                 System.out.print(" ");
  20.             }
  21.             for (int i = 0; i < stars ; i++) {
  22.                 System.out.print("* ");
  23.             }
  24.             System.out.println();
  25.         }
  26.  
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement