iLLcheff

Quadratic Equation

Sep 11th, 2022
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class ExerciseFive {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String inputOne = scanner.nextLine();
  9.         double a = Double.parseDouble(inputOne);
  10.  
  11.         String inputTwo = scanner.nextLine();
  12.         double b = Double.parseDouble(inputTwo);
  13.  
  14.         String inputThree = scanner.nextLine();
  15.         double c = Double.parseDouble(inputThree);
  16.  
  17.         double d = b * b - 4 * a * c;
  18.         double x1 = (-b - Math.sqrt(d)) / (2 * a);
  19.         double x2 = (-b + Math.sqrt(d)) / (2 * a);
  20.  
  21.         DecimalFormat format = new DecimalFormat("0.#");
  22.         System.out.println("x1 = " + format.format(x1) + "; x2 = " + format.format(x2));
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment