Skip to Content

Java float Example

  1. /*
  2.         Java float Example
  3.         This Java Example shows how to declare and use Java primitive float variable
  4.         inside a java class.
  5. */
  6.  
  7. import java.util.*;
  8.  
  9. public class JavaFloatExample {
  10.  
  11.         public static void main(String[] args) {
  12.                
  13.                 /*
  14.                  * float is 32 bit single precision type and used when fractional precision
  15.                  * calculation is required.
  16.                  *
  17.                  * Declare float varibale as below
  18.                  *
  19.                  * float <variable name> = <default value>;
  20.                  *
  21.                  * here assigning default value is optional.
  22.                  */
  23.  
  24.                 float f = 10.4f;
  25.                 System.out.println("Value of float variable f is :" + f);                
  26.         }
  27. }
  28.  
  29. /*
  30. Output would be
  31. Value of float variable f is :10.4
  32. */

Advertisement: