-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEquation.java
36 lines (29 loc) · 976 Bytes
/
Equation.java
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
import java.util.*;
public class Equation{
public static void main(String [] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Input a:");
double a=input.nextDouble();
System.out.print("Input b:");
double b=input.nextDouble();
System.out.print("Input c:");
double c=input.nextDouble();
double result=b*b-4.0*a*c;
if(result>0)
{
double positiveNo=(-b + Math.pow(result,0.5)/(2*a));
double negativeNo=(-b - Math.pow(result,0.5)/(2*a));
System.out.println("The root are "+positiveNo+" and "+negativeNo+".");
}
else if(result==0)
{
double num= -b /(2 * a);
System.out.println("The root is "+num);
}
else
{
System.out.println("The given equation has no real root.");
}
}
}