| @@ -0,0 +1,28 @@ | |||||
| package tutorial; | |||||
| import java.util.Scanner; | |||||
| public class CalRootOfQuadEq { | |||||
| public static void main (String[] args) { | |||||
| int a, b, c; | |||||
| double x1, x2, delta; | |||||
| Scanner input = new Scanner(System.in); | |||||
| System.out.print("Enter a : "); | |||||
| a = input.nextInt(); | |||||
| System.out.print("Enter b : "); | |||||
| b = input.nextInt(); | |||||
| System.out.print("enter c : "); | |||||
| c = input.nextInt(); | |||||
| //-b plus or minus delta and divided by 2a | |||||
| //delta = sqaure root of (b square minus 4ac) | |||||
| delta = Math.sqrt(((Math.pow(b,2)-(4*a*c)))); | |||||
| x1 = ((-b) + delta )/ 2*a; | |||||
| x2 = ((-b) - delta )/ 2*a; | |||||
| System.out.printf("%s%.2f%s%.2f\n", "x1= ",x1,", x2= ",x2); | |||||
| } | |||||
| } | |||||