Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package quadraticcalculator;
- import java.util.Scanner;
- public class QuadraticCalculator {
- public static void main(String[] args) {
- // Prompt user to enter the values for a b and c
- System.out.print("Enter value for a: ");
- Scanner scan = new Scanner(System.in);
- double a = scan.nextInt();
- System.out.print("Enter the value for b: ");
- double b = scan.nextInt();
- System.out.print("Enter for value for c: ");
- double c = scan.nextInt();
- double x1 = (-b + (Math.sqrt((b*b - ((4 * a * c))))))/ (2 * a);
- double x2 = (-b - (Math.sqrt((b*b - ((4*a*c))))))/ (2 * a);
- if (((b*b - ((4 * a * c))) < 0) == true){
- System.out.println("This equation is unsolvable.");
- }
- else if(((b*b - ((4 * a * c))) < 0) == false){
- System.out.println("X is eaqual to: " + x1);
- System.out.println("X is eaqual to: " + x2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment