高分悬赏:Java语言输入一个包含xy的方程,再输入一个y的值,怎么计算对应的x
方程中的变量跟 Java 的变量是一样的,需要先对方程进行转换为 x 为 y 的一个表达式,然后就可以用变量直接得到计算结果了。
给定一个二元一次方程组,形如:
a * x + b * y = c;
d * x + e * y = f;
x,y代表未知数,a, b, c, d, e, f为参数。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
int f = sc.nextInt();
int y = (f*a - d*c)/(a*e-d*b);
int x = (c-b*y)/a;
System.out.print(x+" ");
System.out.println(y);
sc.close;
}
}**