import java.io.*;
public class Test2java
{
/**
* @param args
*/
public static void main(String[] args)throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
int a =Integer.parseInt(s);
int b=Integer.parseInt(br.readLine()); int c=Integer.parseInt(br.readLine());
double d1=(-b)+Math.sqrt(b*b-4*a*c)/(2*a);
System.out.println("方程第一个根是:"+d1);
double d2=(-b)-Math.sqrt(b*b-4*a*c)/(2*a);
System.out.println("方程第二个根是:"+d2);
}
}还有这个出来
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:504)
at java.lang.Integer.parseInt(Integer.java:527)
at Test2java.main(Test2java.java:20)
public class Test2java
{
/**
* @param args
*/
public static void main(String[] args)throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
int a =Integer.parseInt(s);
int b=Integer.parseInt(br.readLine()); int c=Integer.parseInt(br.readLine());
double d1=(-b)+Math.sqrt(b*b-4*a*c)/(2*a);
System.out.println("方程第一个根是:"+d1);
double d2=(-b)-Math.sqrt(b*b-4*a*c)/(2*a);
System.out.println("方程第二个根是:"+d2);
}
}还有这个出来
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:504)
at java.lang.Integer.parseInt(Integer.java:527)
at Test2java.main(Test2java.java:20)
int b=Integer.parseInt(br.readLine());int c=Integer.parseInt(br.readLine());应该这里格式化的时候你输入了非数字字符
这里面的参数必须为数字型的字符串,比如 “123”。
比如参数是"24"就正确,但是如果是" 24"就会出错。
System.out.println(c);可以了。谢谢大家啊。