Sunday, July 27, 2014

Java Basics 103 - Short and Float Variables

---
Java Basics 103 – Short and Float Variables

STEPS

1) Browse http://ideone.com/O5GIga 

2) Change the variables properties to Float Data Types.

Change line no.13 to:

float first_number, second_number, answer;
Change line no.14, 15 to:

first_number = 10.5f;
second_number = 20.8f;
Outcome:

3) Change the Operator to Division

Change the operator in line no.16 from “+” to “/”.
Outcome:

4) Double Variables

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.)

REFERENCE

 

---

No comments:

Post a Comment