用java语言编写程序~~

来源:百度知道 编辑:UC知道 时间:2024/06/06 13:00:39
用文本数据流的方式输入a、b、c,求一元二次方程的根。
谢谢谢谢谢谢谢谢谢谢谢谢谢大家!!!!!

import java.io.*;
public class java {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("please input a");
String str=br.readLine();
float a=Integer.parseInt(str);
System.out.println("please input b");
str=br.readLine();
float b=Integer.parseInt(str);
System.out.println("please input c");
str=br.readLine();
float c=Integer.parseInt(str);
float d=2*a;
float dt=b*b-4*a*c;
if (dt>=0) {
System.out.println("x1="+(Math.sqrt(dt)/d-b/2*a)+" x2="+(-Math.sqrt(dt)/d-b/2*a));
}
else
System.out.println("无实数根");
}
}