-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.java
More file actions
26 lines (20 loc) · 820 Bytes
/
Project.java
File metadata and controls
26 lines (20 loc) · 820 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
import java.util.Scanner;
public class Project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a value for a, b, c: ");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
double discriminant = (Math.pow(b, 2) - (4 * a * c));
System.out.print("The equation has ");
if (discriminant > 0) {
double root1 = ((-b + Math.pow(discriminant, 0.5)) / 2 * a);
double root2 = ((-b - Math.pow(discriminant, 0.5)) / 2 * a);
System.out.print("two roots " + root1 + " and " + root2);
} else if (discriminant == 0) {
double root1 = ((-b + Math.pow(discriminant, 0.5)) / 2 * a);
System.out.print("one root " + root1);
} else System.out.print("no roots");
}
}