java - it isn't reading my number inputs in the original class -
my code isn't seeing input numbers second class. keeps thinking inputs 0 isn't completing program. did go wrong?
i've tried couple different things think of, didn't work. keeps outputting false/unsolvable because numbers 0 instead of inputs.
the second class number inputs.
private static int a, b, c, d, e, f; public static void main(string args[]) { system.out.println("please enter numbers '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; }
you creating new instance of chapter9_2ndclass
, exercise_09_11
, , assigning private static int
s through constructors.
primitive int
defaults 0
when unassigned in context, hence 0
s.
you want assign them parsing arguments of command-line execution int
in main
method.
Comments
Post a Comment