Java Online Compiler
Example: Rhombus Pattern in Java language of Stars using Function
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Rhombus Pattern in Java language of Stars using Function import java.util.Scanner; public class Main { // It's the driver method public static void main(String[] args) { Scanner in = new Scanner(System.in); Main main = new Main(); int x; // x - denotes the number of rows System.out.println("-----Enter the total number of rows-----"); x = in.nextInt(); if (x > 0) { // calling function to print the pattern main.rhombusPattern(x); } } // It will print the rhombus pattern int rhombusPattern(int x) { int i, j; for (i = 1; i <= x; i++) { // print the spaces for (j = i; j < x; j++) System.out.print(" "); // print the stars for (j = 1; j <= x; j++) System.out.print("*"); System.out.print("\n"); } return 0; } }
7
Output
Clear
ADVERTISEMENTS