A. Introduction
If your expressions calculate square roots, power, absolute values etc, you might need standard functions (also called methods, "functions" and "methods" can be used interchangeably). For instance, if we need to calculate square root, we use a standard method Math.sqrt().
Define three variables, a, b and c. Let a=2, b=-1, c=-21. Please write Java code to solve the values of the express to the left.
B. Standard methods are provided to us in Java Standard Library. We just use them. Common Math Functions(Methods) in Java are listed here:
C. Try(HW):
R4.4, R4.5, E4.4
class quadraticEquation {
public static void main() {
int a=2;
int b=-1;
int c=-21;
System.out.println("x=" + ((-b + Math.sqrt(b*b - 4*a*c))/(2*a)) + " or " + ((-b - Math.sqrt(b*b - 4*a*c))/(2*a)));
}
}
x=3.5 or -3.0