70.7k views
2 votes
What is wrong with:

int s = Math.sqrt(49);

User Yekta
by
8.1k points

1 Answer

6 votes

Final answer:

The code is assigning a double value to an integer variable. The variable should be changed to double.

Step-by-step explanation:

The error in the code is that the Math.sqrt function returns a double value, but the result is being assigned to an integer variable.

To fix this, you should change the data type of the variable s to double instead of int.

Here is the corrected code:

double s = Math.sqrt(49);

User Peo Bondesson
by
8.5k points