Tuesday, 24 July 2012

Java float Example


/*
        Java float Example
        This Java Example shows how to declare and use Java primitive float variable
        inside a java class.
*/

import java.util.*;

public class JavaFloatExample {

        public static void main(String[] args) {
             
                /*
                 * float is 32 bit single precision type and used when fractional precision
                 * calculation is required.
                 *
                 * Declare float varibale as below
                 *
                 * float <variable name> = <default value>;
                 *
                 * here assigning default value is optional.
                 */

                float f = 10.4f;
                System.out.println("Value of float variable f is :" + f);              
        }
}

/*
Output would be
Value of float variable f is :10.4
*/

No comments:

Post a Comment