-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealRoots.java
More file actions
41 lines (37 loc) · 1.08 KB
/
Copy pathRealRoots.java
File metadata and controls
41 lines (37 loc) · 1.08 KB
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
34
35
36
37
38
39
40
41
package ifStatement.review;
import java.io.DataInputStream;
import java.io.IOException;
public class RealRoots {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
DataInputStream input = new DataInputStream(System.in);
int a,b,c;
double x1,x2;
System.out.print("Enter the value of 'a'");
a=Integer.parseInt(input.readLine());
if (a==0)
{
System.out.println("That equation is not a quadratic equation");
System.exit(0);
}
System.out.print("Enter the value of 'b'");
b=Integer.parseInt(input.readLine());
System.out.print("Enter the value of 'c'");
c=Integer.parseInt(input.readLine());
if (b*b-4*a*c<0)
{
System.out.println("that Quadratic equation has no real roots");
}
else if (b*b-4*a*c==0)
{
x1=-b/(2*a);
System.out.println("There is one root x="+x1);
}
else if (b*b-4*a*c>0)
{
x1=(-b+Math.sqrt(b*b-4*a*c)/(2*a));
x2=(-b-Math.sqrt(b*b-4*a*c)/(2*a));
System.out.println("There are two real roots for x, where x1="+x1+" and x2="+x2);
}
}
}