skipter icon

Rhombus of Stars - Drawing with Loops - Java

skipter | PRO | 04/13/17 12:08:28 PM UTC | 0 ⭐ | 309 👁️ | Never ⏰ | []
Java |

810 B

|

None

|

0 👍

/

0 👎

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = Integer.parseInt(input.nextLine());
 
        for (int stars = 1; stars <= n; stars++) {
            for (int j = 0; j < n - stars; j++) {
                System.out.print(" ");
            }
            for (int i = 1; i <= stars ; i++) {
                System.out.print("* ");
            }
            System.out.println();
        }
 
        for (int stars = n - 1; stars >= 1; stars--) {
            for (int j = 0; j < n - stars; j++) {
                System.out.print(" ");
            }
            for (int i = 0; i < stars ; i++) {
                System.out.print("* ");
            }
            System.out.println();
        }
 
    }
 
}

Comments