Shavit

Quadratic Equation V1

Oct 8th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class QuadraticEquationV1 {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.         int a, b, c;
  13.        
  14.         System.out.println("Enter the values of a, b and c for the quadratic equation:");
  15.         a = in.nextInt();
  16.         b = in.nextInt();
  17.         c = in.nextInt();
  18.        
  19.         double delta = Math.pow((double)b, 2) - 4 * a * c;
  20.         double x1 = (-b + Math.sqrt(delta)) / (2 * a);
  21.         double x2 = (-b - Math.sqrt(delta)) / (2 * a);
  22.        
  23.         System.out.printf("Your roots are %.2f and %.2f", x1, x2);
  24.        
  25.         in.close();
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment