Java 它不是';I don’我不在原来的课堂上读我的数字输入
我的代码没有看到第二个类的输入数字。它一直认为所有的输入都是零,所以它没有完成程序。我哪里出错了 我试过一些我能想到的不同的方法,但都不管用。它不断输出false/Unsolved,因为所有数字都是零,而不是输入 第二类就是数字输入Java 它不是';I don’我不在原来的课堂上读我的数字输入,java,class,methods,input,Java,Class,Methods,Input,我的代码没有看到第二个类的输入数字。它一直认为所有的输入都是零,所以它没有完成程序。我哪里出错了 我试过一些我能想到的不同的方法,但都不管用。它不断输出false/Unsolved,因为所有数字都是零,而不是输入 第二类就是数字输入 private static int a, b, c, d, e, f; public static void main(String args[]) { System.out.println("Please enter numbers for 'a, b
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;
}
您正在创建
第9章\u 2ndclass
和练习\u 09\u 11
的新实例,并通过其构造函数将您的私有静态int
分配给它
原语int
在此上下文中取消分配时默认为0
,因此您可以获得所有0
s
您可能希望通过在
main
方法中将命令行执行的参数解析为int
来分配它们。所有变量都是零,因为它们没有初始化,您将变量传递给第9章第2节类和练习第11节的构造函数,这会导致int的默认值ie0
被传递并将其初始化为0
问题在于,您从未从用户处读取任何输入并设置值。具体来说,静态int声明a、b、c、d、e和f默认为0,并且从不设置