我的代碼沒有看到來自第二類的輸入數字。它一直認爲所有的輸入都是零,所以它沒有完成程序。我哪裏做錯了?它不讀取我在原始類中的數字輸入
我試過了幾個不同的東西,我可以想到,但它沒有奏效。它不斷輸出錯誤/無法解析,因爲所有數字都是零而不是輸入。
第二類只是數字輸入。
private static int a, b, c, d, e, f;
public static void main(String args[]) {
System.out.println("Please enter numbers for 'a, b, c, d, e, f' ");
Chapter9_2ndclass c2 = new Chapter9_2ndclass(a, b, c, d, e, f);
Exercise_09_11 Chapter9_2ndclass = new Exercise_09_11(a, b, c, d, e, f);
// Exercise_09_11 getY = new Exercise_09_11(a, b, c, d, e, f);
// //constructors
if (Chapter9_2ndclass.isSolvable()) {
Chapter9_2ndclass.getX();
Chapter9_2ndclass.getY();
} else {
System.out.println("Unsolvable");
}
}
public Exercise_09_11(int a, int b, int c, int d, int e, int f) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
}
public boolean isSolvable() {
double isSolvable = ((a * d) - (b * c));
System.out.println(isSolvable);
if (isSolvable != 0) {
System.out.println("True");
return true;
} else {
System.out.println("False");
System.out.println("The 'isSolvable' number is, " + isSolvable);
return false;
}
}
public int getY() {
int Y = ((a * f) - (e * c))/((a * d) - (b * c));
return Y;
}
public int getX() {
int X = ((e * d) - (b * f))/((a * d) - (b * c));
return X;
}