Advertisement
kaloyan99

Untitled

Feb 24th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class QuadraticEquation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double a = scanner.nextInt();
  8.         double b = scanner.nextInt();
  9.         double c = scanner.nextInt();
  10.  
  11.         double d = b * b - 4 * a * c;
  12.  
  13.         double x1 = (- b - Math.sqrt(d)) / (2 * a);
  14.         double x2 = (- b + Math.sqrt(d)) / (2 * a);
  15.  
  16.         if (x1 == (int)x1) {
  17.             System.out.print("x1=" + (int)x1 + ";");
  18.         }else System.out.print("x1=" + x1 + ";");
  19.  
  20.         if (x2 == (int)x2) {
  21.             System.out.print("x2=" + (int)x2 + ";");
  22.         }else System.out.print("x2=" + x2 + ";");
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement