Advertisement
cyanide_red

Quadratic

Oct 11th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. class Quadratic {
  2. public static void main(String[] args)
  3. {
  4. int a = 2;
  5. int b = 20;
  6. int c = 6;
  7. double x1 = 0;
  8. double x2 = 0;
  9. double D = (b * b) - (4 * a * c);
  10. if (D > 0) {
  11. x1 = (int) (-b + Math.sqrt(D)) / (2 * a);
  12. x2 = (int) (-b - Math.sqrt(D)) / (2 * a);
  13. System.out.println("x1 = " + x1 + "; x2 = " + x2);
  14. }
  15. else if (D == 0) {
  16. x1 = (int) (-b) / (2 * a);
  17. System.out.println("x1 = " + x1);
  18. }
  19. else if (D < 0) {
  20. System.out.println("Уравнение не имеет корней! D < 0!");
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement