Java Basics 103 – Short and Float Variables
Change line no.13 to:
float first_number, second_number, answer; |
Change line no.14, 15 to:
first_number = 10.5f; |
Outcome:
Change the operator in line no.16 from “+” to “/”.
Outcome:
Change the Data Type for variables in line no.13 to Double.
Outcome:
Lessons:
When you use Float Data Type, the answer was 0.5048077. Java has taken the first 6 numbers after the point and then rounded up the rest.
However, the double variable type can hold more numbers than float. (Double is a 64 bit number and float is only 32 bit.)
http://www.homeandlearn.co.uk/java/short_float_variables.html