package hwoneweek; |
//求方程aX^2+bX+c=0的实数解。要求:a、b、c的值从键盘输入 |
import java.util.Scanner; |
public class xcheng{ |
public static void main(String[] args){ |
double x = 0 ; |
double i ,i1 = 0 ; |
System.out.println( "求方程aX^2+bX+c=0的实数解,请按提示输入!" ); |
Scanner input = new Scanner(System.in); |
System.out.println( "请输入a:" ); |
double a = input.nextDouble(); |
System.out.println( "请输入b(注意a和b不能同时为0):" ); |
double b = input.nextDouble(); |
System.out.println( "请输入c:" ); |
double c = input.nextDouble(); |
i = b*b- 4 *a*c; |
if (a == 0 ){ |
if (b == 0 ) |
System.out.println( "a和b同时为0,输入错误!!!" ); |
else { |
x = c/b; |
System.out.println( "x=" +x); |
} |
} |
else { |
if (i< 0 ) |
System.out.println( "方程无实数解!" ); |
else { |
i1 = Math.sqrt(i); |
System.out.println( "方程的实数解为:" ); |
x = (-b+i1)/( 2 *a); |
System.out.println( "x1=" +x); |
x = (-b-i1)/( 2 *a); |
System.out.println( "x2=" +x); |
} |
} |
} |
} |
|
|
|
中级程序员
by: sxdfr 发表于:2017-04-16 22:04:10 顶(0) | 踩(0) 回复
不错
回复评论