Build a calculator

I created a div() method that return double value

public double div(int a, int b){
    double div = a/b;
    return div;

when I print this method using an obj myCalculator and with parameters say (5,4) then it prints a double value 1.0.

why is it not showing correct result?

when you assign double div = a/b;, a and b are still integers. You have to make them doubles at some point if you want a real number result.

1 Like