/* Name: penis
This program solve a quadratic expression (Use case ex: a = 1, b = 3, c = -4)
*/
import java.util.*;
import static java.lang.System.*;
public class Quadratic {
public static void main(String[] args ) {
Scanner reader = new Scanner(System.in);
int a = 0;
int b = 0;
int c = 0;
int discriminant = 0;
double rootOne = 0.0;
double rootTwo = 0.0;
System.out.print("Enter the value for 'a':\n");
a = reader.nextInt();
System.out.print("Enter the value of 'b':\n");
b = reader.nextInt();
System.out.print("Enter the value of 'c':\n");
c = reader.nextInt();
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
rootOne = (-b + Math.sqrt(discriminant)) / (2 * a);
rootTwo = (-b - Math.sqrt(discriminant)) / (2 * a);
System.out.printf("rootOne :: %.2f \n" , rootOne);
System.out.printf("rootTwo :: %.2f \n", rootTwo);
} else if (discriminant == 0) {
rootOne = (-b) / (2 * a);
System.out.printf("rootOne :: %.2f\n", rootOne);
} else {
System.out.printf("Imaginary roots");
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: