LZ其实应该自己试着做一下,我这里写了完整的解答,还有结果,自己看吧!
1. ===========================TestEx1_2.java:===========================
import java.util.*;
public class TestEx1_2 {
public static void main(String[] args) {
// read in from keyboard
Scanner s = new Scanner(System.in);
System.out.print("Please enter a: ");
double a = s.nextDouble();
System.out.print("Please enter b: ");
double b = s.nextDouble();
System.out.print("Please enter c: ");
double c = s.nextDouble();
System.out.print("Please enter d: ");
double d = s.nextDouble();
System.out.print("Please enter e: ");
double e = s.nextDouble();
System.out.print("Please enter f: ");
double f = s.nextDouble();
// calculate using Ex1_2
Ex1_2 ex = new Ex1_2(a,b,c,d,e,f);
if (ex.isConsistent())
System.out.println("The result x = "+ex.getX()+", and y = "+ex.getY());
else
System.out.println("The answer is not consistent, the denominator is zero!");
}
}
2. ===========================Ex1_2.java:===========================
public class Ex1_2 {
private double a,b,c,d,e,f;
private double x,y;
public Ex1_2(double a1,double b1,double c1,double d1,double e1,double f1) {
a = a1;
b = b1;
c = c1;
d = d1;
e = e1;
f = f1;
}
public double getX()
{
x = (c*e-b*f) / (a*e-b*d);
return x;
}
public double getY ()
{
y = (a*f-c*d) / (a*e-b*d);
return y;
}
public boolean isConsistent()
{
double denominator = (a*e-b*d);
if (denominator==0)
return false; // wrong
else
return true;
}
}
3. ===========================Sample output:===========================
Please enter a: 2.0
Please enter b: 2.0
Please enter c: 3.0
Please enter d: 2.3
Please enter e: 5.0
Please enter f: 3.56
The result x = 1.459259259259259, and y = 0.040740740740740855
Please enter a: 4.0
Please enter b: 2.0
Please enter c: 3.0
Please enter d: 4.0
Please enter e: 2.0
Please enter f: 6.0
The answer is not consistent, the denominator is zero!
大哥,,,好痛苦哦,全英语,,
看不清啊