-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuadraticEquation.java
More file actions
30 lines (26 loc) · 1017 Bytes
/
QuadraticEquation.java
File metadata and controls
30 lines (26 loc) · 1017 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
import java.util.Scanner;
public class QuadraticEquation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter value of A: ");
int a = sc.nextInt();
System.out.print("Enter value of B: ");
int b = sc.nextInt();
System.out.print("Enter value of C: ");
int c = sc.nextInt();
int d = b * b - 4 * a * c;
if (d > 0) {
double root1 = (-b + Math.sqrt(d)) / (2 * a);
double root2 = (-b - Math.sqrt(d)) / (2 * a);
System.out.println("Roots are real and different.");
System.out.println("Root1 = " + root1);
System.out.println("Root2 = " + root2);
} else if (d == 0) {
double root = -b / (2.0 * a);
System.out.println("Roots are real and equal.");
System.out.println("Root = " + root);
} else {
System.out.println("Roots are imaginary (no real roots).");
}
}
}