2.6
![](https://i-blog.csdnimg.cn/blog_migrate/8a0213c575313f4823fe5ab146b6767d.png)
package booksTest;
import seventh.ScannerFileTest;
import java.util.Scanner;
public class p34_2_6 {
public static void main(String[] args) {
/*
题目要求
编写程序 ,要求用户从键盘输入a 、b 、和c的值,计算下列表达式的值
*/
Scanner sc = new Scanner(System.in);
for (int i = 0; i <10 ; i++) {
System.out.println("请输入a的值");
double a = sc.nextDouble();
System.out.println("请输入b的值");
double b = sc.nextDouble();
System.out.println("请输入c的值");
double c = sc.nextDouble();
double e = Math.sqrt(b * b - 4 * a * c);
double f = -b + e;
if (e > 0) {
System.out.println("表达式的值为" + f / 2 * a);
return;
} else {
System.out.println("你输入的值b^2-4ac小于0");
}
}
}
}