Java Program To Calculate Square Root Of A Number

Posted on  by  admin
Calculate

Java Program To Calculate Square Root Of A Number

In the above program, the coefficients a, b and c are set to 2.3, 4 and 5.6 respectively. Then, the determinant is calculated as b 2 - 4ac.Based on the value of determinant, the roots are calculated as given in the formula above.

Program

Notice we've used library function Math.sqrt to calculate the square root of a number.The calculated roots (either real or complex) are printed on the screen using format function in Java. The format function can also be replaced by printf as:System.out.printf('root1 = root2 =%.2f;', root1).

Coments are closed