78.5k views
2 votes
When compiling a program you received the following error: PowerSquare.java:15: error: incompatible types: possible lossy conversion from double to int result = Math.pow(base2, pow); What is the reason for the error?

User Stopshinal
by
5.5k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

The main reason for this error is that the piece of code "Math.pow(base2, pow)" takes those values, applies the mathematic function to it, and returns a value that is a double but you are trying to save it within an int variable. Therefore since both of these are different the error pops up telling you that these two types are incompatible, one is an int and the other is a double. In order to solve this, you would need to save the results from the "Math.pow(base2, pow)" into a variable of type double.

User Bahaa Hany
by
4.8k points