a410.
解方程
--
TYVJ
| From: [36.228.37.61] |
發表日期
:
2014-08-14 11:42
第 9 測資點(0%): RE (code:1) 執行時期錯誤您的程式被監控系統中斷,可能是程式無法正常結束所導致。 Exception in thread "main" java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1011) at java.lang.Float.parseFloat(Float.java:452) at code_1928080.main(code_1928080.java:24)
以下是我程式碼:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class a290 {
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
String input;
while ((input = buf.readLine()) != null) {
String [] array = input.split(" ");
//求解x,y
float x,y;
//行列式
float [][] linerow = new float[2][3];
int temp=0;
for(int row=0;row<2;row++){
for(int line=0;line<3;line++){
linerow[row][line] = Float.parseFloat(array[temp]);
temp++;
}
}
//delta = ad-bc
float delta = linerow[0][0]* linerow[1][1] - linerow[0][1]*linerow[1][0];
//deltax = c1*d - b*c2
float deltax = linerow[0][2]* linerow[1][1] - linerow[0][1]*linerow[1][2];
//deltay = a*c2 - c1*c
float deltay = linerow[0][0]* linerow[1][2] - linerow[0][2]*linerow[1][0];
if(delta!=0){
x = deltax/delta;
y = deltay/delta;
System.out.printf("x=%.2f\n" , x);
System.out.printf("y=%.2f" , y);
}
else if(delta==0 && (deltax!=0 || deltay!=0)){
System.out.println("No answer");
}
else if(delta==0 && deltax==0 && deltay==0){
System.out.println("Too many");
}
}
}
}