Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
28 lines (26 loc) · 1.09 KB

File metadata and controls

28 lines (26 loc) · 1.09 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package java_core;
import java.util.Scanner;
import java.lang.Math;
public class QuadraticEquation {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Quadratic equation = ax^2+bx+c=0. Kindly enter the value of a : ");
int a = sc.nextInt();
System.out.println("Quadratic equation = ax^2+bx+c=0. Kindly enter the value of b : ");
int b = sc.nextInt();
System.out.println("Quadratic equation = ax^2+bx+c=0. Kindly enter the value of c : ");
int c = sc.nextInt();
double discriminant = ((b*b) - (4*a*c));
double root1 = (-b + Math.sqrt(discriminant))/(2*a);
double root2 = (-b - Math.sqrt(discriminant))/(2*a);
if (discriminant==0){
System.out.println("The value of root (x) is : "+root1);
}
else if(discriminant>0){
System.out.println("The roots are unequal real roots. The values of roots are: "+root1 +" and "+root2);
}
else{
System.out.println("this equation has no real roots");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.