UNIX

Quadratic Formula Calculator

Dec 23rd, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. package quadraticcalculator;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class QuadraticCalculator {
  6.     public static void main(String[] args) {
  7.             // Prompt user to enter the values for a b and c
  8.         System.out.print("Enter value for a: ");
  9.         Scanner scan = new Scanner(System.in);
  10.         double a = scan.nextInt();
  11.        
  12.         System.out.print("Enter the value for b: ");
  13.         double b = scan.nextInt();
  14.        
  15.         System.out.print("Enter for value for c: ");
  16.         double c = scan.nextInt();
  17.        
  18.         double x1 = (-b + (Math.sqrt((b*b - ((4 * a * c))))))/ (2 * a);
  19.         double x2 = (-b - (Math.sqrt((b*b - ((4*a*c))))))/ (2 * a);
  20.        
  21.         if (((b*b - ((4 * a * c))) < 0) == true){
  22.             System.out.println("This equation is unsolvable.");
  23.         }
  24.         else if(((b*b - ((4 * a * c))) < 0) == false){
  25.             System.out.println("X is eaqual to: " + x1);
  26.             System.out.println("X is eaqual to: " + x2);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment