一个简单的java代码
补充:package 两个数求和等;
import java.io.*;
public class tao3 {
public static void abc(double a,double b,double c){
if(b*b-4*a*c>=0)
return ;
System.out.println("得到的根为"+(-b+Math.sqrt(b*b-4*a*c)/(2*a))+(-b-Math.sqrt(b*b-4*a*c)/(2*a)));
if(b*b-4*a*c<0)
System.out.println("无解");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
InputStreamReader isr=new InputStreamReader(System.in );
BufferedReader br=new BufferedReader(isr);
System.out.println("请输入a");
String a=br.readLine();
float n1=Float.parseFloat(a);
System.out.println("请输入b");
String b=br.readLine();
float n2=Float.parseFloat(b);
System.out.println("请输入c");
String c=br.readLine();
float n3=Float.parseFloat(c);
abc(n1,n2,n3);
}catch(Exception e){
e.printStackTrace();
}
}
}
假设a=1 b=5 c=4