/**
* 代數方面:求解2X2線性方程。
* ax+by=e; cx+dy=f; x =(ed-bf)/(ad-bc); y=(af-ec)/(ad-bc)
* 提示用戶輸入a、b、c、d、e和f。
* 然後顯示結果。
* 如果ad-bc爲0,報告消息“The equation has no solution!”。
*/
package Test;
import java.util.Scanner;
public class T33Scanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a, b, c, d, e, f: ");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
double d = input.nextDouble();
double e = input.nextDouble();
double f = input.nextDouble();
double adbc = (a * d - b * c);
double x = (e * d - b * f) / adbc;
double y = (a * f - e * c) / adbc;
System.out.println((adbc == 0) ? "The equation has no solution!" : "x is " + x + " and y is " + y);
// if ((a * d - b * c) == 0)
// System.out.println("The equation has no solution!");
// else
// System.out.println("x is " + x + " and y is " + y);
// boolean even = ((a * d - b * c) == 0);
// if (even == true)
// System.out.println("x is " + x + " and y is " + y);
// else
// System.out.println("The equation has no solution!");
}
}
第3章:代數方面:求解2X2線性方程
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.