|
KvUravn
╬яшёрэшх:
╧ЁюуЁрььр, яючтюы ■∙р Ёх°рЄ№ ътрфЁрЄэ√х єЁртэхэш . ╨рсюЄрхЄ яюф ёшёЄхьющ.
(╥.х. ўЄюс√ хх чряєёЄшЄ№, эєцэю ёърўрЄ№ ёхсх KvUravn.class, р яюёых, т ъюьрэфэющ ёЁюъх
эряшёрЄ№: " java KvUravn ".)
╧ЁюуЁрььр:
import java.io.*;
class kvuravn {
public static void main(String args[])
throws IOException
{
DataInputStream inData = new DataInputStream(System.in);
String str;
int a;
int b;
int c;
int sum=0;
System.out.println("Введите переменную при x квадрате");
str = inData.readLine();
try {
a = Integer.parseInt(str);
} catch(NumberFormatException e) {
System.out.println("Вы должны указать число!");
a = 1;
}
System.out.println("Введите переменную при x");
str = inData.readLine();
try {
b = Integer.parseInt(str);
} catch(NumberFormatException e) {
System.out.println("Вы должны указать число!");
b = 1;
}
System.out.println("Введите значение свободного члена");
str = inData.readLine();
try {
c = Integer.parseInt(str);
} catch(NumberFormatException e) {
System.out.println("Вы должны указать число!");
c = 1;
}
double e, d, x1, x2, x3;
e = 0;
d = (b * b)-(4 * a * c);
double f = Math.sqrt(d);
x1 = (f - b)/(2 * a);
x2 = (-f -b)/(2 * a);
x3 = (-b)/(2 *a);
System.out.println (" ");
System.out.println ("Результат запроса, при a = "+a + ", b = "+ b +", c = "+ c + ":");
System.out.println (" ");
System.out.println ("Дискриминант = "+ d);
if (d >= e) System.out.println ("Корень из дискриминанта = "+ f);
if (d < e) System.out.println
("Решения нет, т.к. дискриминант меньше нуля");
if (d > e) System.out.println ("Существует 2 решения:");
if (d > e) System.out.println ("Первое решение: x ="+ x1);
if (d > e) System.out.println ("Второе решение: x ="+ x2);
if (d == e) System.out.println ("Существует 1 решение, т.к. дискриминант равен нулю");
if (d == e) System.out.println ("Решение: x ="+ x3);
while(a != 0); while(b != 0);
}
}
| |
|