I'm currently taking a class in learning java.
Anyways, I am doing a code that was provided and has an error.
We are suppose to review and figure out why it's giving the error and how to fix it.
You coded the following in class Test.java:
The code compiles properly and runs, but the result is not what youint a = 32; int b = 10; double c = a / b; System.out.println( “The value of c is “ + c );
expected. The output is
The value of c is 3.0
You expected the value of c to be 3.2. Explain what the problem is and
how to fix it.
So the problem is the left over value. In the chapter I read it spoke about using % to bring out the remainder. But all the options I could think of wouldn't work.
This is what I wrote with some modification on the original script
int a = 32, b = 10; double c = (double)a/b; c%=c; //tried to float c but that gives the same answer. The issue I believe is a rounding // I know % would be right trick to pull the extra digits. System.out.println("The value of c is " + c); System.exit(0);
I would appreciate any assistance on this
I also tried playing around with
int a, b; double c; b = 10; a = 32; c = a%b;