Westonci.ca is the Q&A platform that connects you with experts who provide accurate and detailed answers. Get immediate and reliable answers to your questions from a community of experienced professionals on our platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

Rewrite the following condition to avoid a possible arithmetic exception:

if (Math.sqrt(x) < 3 && x > 7)


Sagot :

Answer:

if (x > 7 && Math.sqrt(x) < 3)

Explanation:

The previous condition checks if the square root of x is less than 3, but this would raise an error if x is a value equal to or less than 0.

So, the condition checks for the value of x before evaluating the square root after the AND operation to prevent an arithmetic exception.