-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquadForm.java
More file actions
33 lines (23 loc) · 903 Bytes
/
quadForm.java
File metadata and controls
33 lines (23 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Author: Leah Benitez
* Created: 2/14/19
* Desc: This program plugs variables provided by the user into the quadratic formula.
*/
import java.util.Scanner;
public class quadForm {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double discriminant;
System.out.println("Please enter the value of a.");
double varA = scnr.nextDouble();
System.out.println("Please enter the value of b.");
double varB = scnr.nextDouble();
System.out.println("Please enter the value of c.");
double varC = scnr.nextDouble();
discriminant = Math.pow(varB, 2) - (4 * varA * varC);
double root1 = (-varB + Math.sqrt(discriminant))/ (2.0 * varA);
double root2 = (-varB - Math.sqrt(discriminant))/ (2.0 * varA);
System.out.println("The root 1 is " + root1);
System.out.println("The root 2 is " + root2);
}
}