printStars is a method that accepts a single int argument an
printStars is a method that accepts a single int argument and returns no value . It prints as many stars as indicated by its argument . Given a variable x of type double that has been given a value , write a statement that invokes printStars passing x as an argument . Assume that printStars is defined in the same class that calls it.
Solution
Hi, Please find my implementation.
public class PrintStar {
// Method 1
public void printStar(int x){
for(int i=1; i<=x; i++){
System.out.print(\"*\");
}
}
// Method 2
public void printStar(double x){
for(int i=1; i<=x; i++){
System.out.print(\"*\");
}
}
public static void main(String[] args) {
// creating an Object
PrintStar p = new PrintStar();
p.printStar(5);
System.out.println();
p.printStar(6.7);
}
}
/*
Sample run:
*****
******
*/

