208k views
4 votes
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.

User Jyosna
by
6.8k points

2 Answers

3 votes

Final answer:

To invoke the printStars method and pass the variable x as an argument, you can write: printStars((int)x); This will cast the double value of x to an integer before passing it to the method.

Step-by-step explanation:

To invoke the printStars method and pass the variable x as an argument, you can write:

printStars((int)x);

This statement will cast the double value of x to an integer and pass it as an argument to the printStars method. The printStars method will then print the corresponding number of stars.

User Solenoid
by
7.4k points
4 votes

Answer:

Incorrect question. You might want to review it.

Step-by-step explanation:

printStars is a method that accepts a single int argument but the variable x that will be passed into the method during its call is of type double. Hence, there is going to be an error.

Hope this helps!

User Yedidya Reiss
by
7.8k points