Rhombus Pattern in Java language of Stars using Function
ADVERTISEMENTS
Rhombus pattern in java language of stars using function. In this article, you will learn how to print the rhombus pattern in java language of stars using function.
Source Code
// 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;
}
}
Output
-----Enter the total number of rows-----
7
*******
*******
*******
*******
*******
*******
*******