Using float Data Type

Practise your skills and try to change the code. Read the comments and try what is within the TODO comment.

class FloatDemo {
    public static void main (String[] args) {
        //A float type holds a floating point number
        //A float is a 32-bit precision floating point number
        //The float value should be prefixed with an F or f
        //If you need very high precision you should use a double data type instead
        float averageScore = 550.50F; 
        float totalScore = 975.05f;
        System.out.println("averageScore " + averageScore);
        System.out.println("totalScore " + totalScore);

        //You can also use scientific notation for the literal value of the float
        float minimumFloatValue = 1.4E-45F;
        float maximumFloatValue = 3.4028235E38F;
        System.out.println("minimumFloatValue " + minimumFloatValue);
        System.out.println("maximumFloatValue " + maximumFloatValue);

        //TODO
        //Try removing the F at the end of the float literal values and Run again
        //Create your own float value and print it to the console
    }
}
  

results matching ""

    No results matching ""