Can someone please help to tell why I'm getting zero in my arithmetic operations? I'm trying to solve this arithmetic problem which gives value of x and y but it's giving me java.lang.arithmeticException error or showing zero result. It will be really helpful to me.
this is my input a=6,b=10,c=8,d=12,e=800,f=900
**This linear equation to obtain the values for x and y can be solved using
x = (ed -fb)/(ad -bc), y = (fa -ec)/(ad – bc)**
this is the problem that i'm trying to solve.
public class linearequation {
public static void main(String[] args){
Scanner scn= new Scanner(System.in);
linear lin1 = new linear(scn.nextInt(),scn.nextInt(),scn.nextInt(),scn.nextInt(),scn.nextInt(),scn.nextInt());
if(lin1.isSolvable()) {
System.out.println(lin1.getx());
System.out.println(lin1.gety());
}else {
System.out.println("No Solution");
}
}
}
class linear {
private int a, b, c, d, e, f;
int x, y;
int den = ((a * d) - (b * c));
public linear(int na, int nb, int nc, int nd, int ne, int nf) {
na = a;
nb = b;
nc = c;
nd = d;
ne = e;
nf = f;
}
public int geta() {
return a;
}
public int getb() {
return b;
}
public int getc() {
return c;
}
public int getd() {
return d;
}
public int gete() {
return e;
}
public int getf() {
return f;
}
public int getx() {
return x = ((e * d) - (f * b)) / den;
}
public int gety() {
return y = ((f * a) - (e * c)) / den;
}
public boolean isSolvable() {
if (den <= 0) {
return false;
} else {
return true;
}
}
}```
denis predefined to be 0 since it is calculated before the constructor can assign values to a, b, c, d, e, and f. You need to set it after assigning the values in the constructor.