我的计算器上有一个程序,它接受2个方程(A系统)的所有值并求解(X,Y)。我正在尝试制作一个程序,但我的程序计算错误。有人可以看看吗?
这是我的代码:
import java.util.Scanner;
public class SystemSolver {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a1 = 0, a2 = 0, b1 = 0, b2 = 0, c1 = 0, c2 = 0;
System.out.println("Enter 'a1': ");
a1 = sc.nextDouble();
System.out.println("Enter 'b1': ");
b1 = sc.nextDouble();
System.out.println("Enter 'c1': ");
c1 = sc.nextDouble();
System.out.println("Enter 'a2': ");
a2 = sc.nextDouble();
System.out.println("Enter 'b2': ");
b2 = sc.nextDouble();
System.out.println("Enter 'c2': ");
c2 = sc.nextDouble();
System.out.println("Your Systems Are (1) " + a1 + " + " + b1 + " = " + c1);
System.out.println(" (2) " + a2 + " + " + b2 + " = " + c2);
double x = ((b1*c2)-(c1*b2))/((b1*a2)-(a1*b2));
double y = ((c1*a2)-(c2*a1))/((b1*a2)-(a1*b2));
System.out.print("\n The Values Of 'X' And 'Y' Are: ");
System.out.print( "(" + x + " , " + y + ")");
}
}