Question: Try to run the following java code: double x = 5 / 2 0 ; System.out.println ( x ) ; What answer do you get?

Try to run the following java code:
double x =5/20;
System.out.println(x);
What answer do you get? The answer is imprecise!
Write a Java program that precisely calculates the decimal value of a fraction, and prints the answer to the screen. The value displayed must be accurate.
Sample Run:
Please enter the numerator:
5
Please enter the denominator:
20
The decimal value is: 0.25

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!