Guest User

Untitled

a guest
May 18th, 2021
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4. public class homework {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         double a = Double.parseDouble(scanner.nextLine());
  8.         double b = Double.parseDouble(scanner.nextLine());;
  9.         double c = Double.parseDouble(scanner.nextLine());;
  10.         double x1, x2;
  11.         double det = b * b - 4 * a * c;
  12.         double sqrt = Math.sqrt(det);
  13.         DecimalFormat pattern = new DecimalFormat("#.##");
  14.         if(det > 0){
  15.             x1 = (-b - sqrt) / 2*a;
  16.             x2 = (-b + sqrt) / 2*a;
  17.             System.out.println("x1=" + pattern.format((x1)));
  18.             System.out.println("x2=" + pattern.format((x2)));
  19.         }
  20.         else if(det == 0){
  21.             x1=x2=-b / (2*a);
  22.             System.out.println("x1=" + pattern.format((x1)));
  23.             System.out.println("x2=" + pattern.format((x2)));
  24.         }
  25.     }
  26. }
  27.  
  28.  
RAW Paste Data