import java.util.Scanner; public class Diskriminant { public static void main(String[] args) { System.out.println("Введите три числа, чтобы подставить их в уравнение: Ax^2 + Bx + C = 0, и найти корни по Дискриминанту: "); try{ Scanner scn = new Scanner(System.in); System.out.print("Введите числа A, B и C: "); String a = scn.nextLine(); int a1 = Integer.parseInt(a); String b = scn.nextLine(); int b1 = Integer.parseInt(b); String c = scn.nextLine(); int c1 = Integer.parseInt(c); if (b1 < 0 && c1 < 0) System.out.println("Уравнение: " + a1 + "x^2 " + b1 + "x " + c1 + " = 0;"); else if ((b1 < 0) && (c1 > 0)) System.out.println("Уравнение: " + a1 + "x^2 " + b1 + "x +" + c1 + " = 0;"); else if ((b1 > 0) && (c1 > 0)) System.out.println("Уравнение: " + a1 + "x^2 +" + b1 + "x +" + c1 + " = 0;"); else System.out.println("Уравнение: " + a1 + "x^2 +" + b1 + "x " + c1 + " = 0;"); System.out.println("D = b^2 - 4ac;"); System.out.println("D = " + b1 + "^2 - 4" + "*" + a1 + "*" + c1 + ";"); int s = (int) Math.pow(b1, 2) - 4 * a1 * c1; System.out.println("D = " + ((int) Math.pow(b1, 2)) + " - " + (4 * a1 * c1) + " = " + s + ";"); if (s < 0) { System.out.println("К сожалению корней нет! т.к. D < 0!"); } else if (s == 0) { int x1 = -b1 / (2*a1); System.out.println("1 корень! т.к. D = 0!"); System.out.println("x1 = -b/2a;"); System.out.println("x1 = " + x1 + ";"); } else { System.out.println("Уравнение имеет 2 корня, т.к D > 0!"); System.out.println("x1,2 = (-b ± √D)/2a;"); int x1 = (int) ((-b1+Math.sqrt(s))/(2*a1)); System.out.println("x1 = " + x1 + ";"); int x2 = (int) ((-b1-Math.sqrt(s))/(2*a1)); System.out.println("x2 = " + x2 + ";"); } }catch (Exception e) {System.out.print("Вы ввели недопустимые данные!\nПожалуйста введи целое число!");}; } }