Answer:
// import the Scanner class
// to allow the program receive user input
import java.util.Scanner;
// The class Solution is defined
public class Solution{
// main method to begin program execution
public static void main(String[] args) {
// scanner object scan is declared
Scanner scan = new Scanner(System.in);
// Prompt the user to enter a number
System.out.println("Enter the number of stars you want: ");
// user input is assigned to numOfStar
int numOfStar = scan.nextInt();
// call the makeStars method
makeStars(numOfStar);
}
// makeStars method print stars using recursion
// the method call itself till starNum == 0
public static void makeStars(int starNum){
if (starNum != 0){
System.out.print("*");
makeStars(starNum -1);
}
}
}
Explanation:
The code is well comment and solve the problem using recursion.