这个java程序运行后结果怎么不正确啊?
import java.io.*;public class hw13_13{
public static void main(String[] args) throws IOException{
Center a=new Center();
double n1,n2,n3,n4,n5;
String str1,str2;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input number: "+"(");
str1=buf.readLine();
String s1=str1.substring(0,2);
String s2=str1.substring(3,5);
String s3=str1.substring(6,8);
String s4=str1.substring(9,11);
String s5=str1.substring(12,14);
n1=Double.parseDouble(s1);
n2=Double.parseDouble(s2);
n3=Double.parseDouble(s3);
n4=Double.parseDouble(s4);
n5=Double.parseDouble(s5);
try{
a.show(n1,n2,n3,n4,n5);
}
catch(CenterException e){
System.out.println(e+" throwed");
}
catch(OutException e){
System.out.println(e+" throwed");
}
catch(InException e){
System.out.println(e+" throwed");
}
}
}
class CenterException extends Exception{
}
class OutException extends Exception{
}
class InException extends Exception{
}
class Center{
double radius;
double x1;
double y1;
double x2;
double y2;
double dist=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
public void show(double x1,double y1,double x2,double y2,double radius) throws
CenterException,OutException,InException{
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
this.radius=radius;
if(dist==0){
System.out.print("("+x1+","+y1+")");
System.out.print("在半径"+radius);
System.out.println(",圆心("+x2+","+y2+")的圆心上");
throw new CenterException();
}
else if(dist<=radius){
System.out.print("("+x1+","+y1+")");
System.out.print("在半径"+radius);
System.out.println(", 圆心("+x2+","+y2+")的圆内");
throw new InException();
}
else{
System.out.print("("+x1+","+y1+")");
System.out.print("在半径"+radius);
System.out.println(", 圆心("+x2+","+y2+")的圆外");
throw new OutException();
}
}
}
--------------------编程问答-------------------- 怎么不正确? --------------------编程问答-------------------- 运行了之后是真确的。
你是不是输入的数字的位数不够导致的错误,输入的数字应该是14位。不能输入字符。
运行之后截图:
补充:Java , Java SE