What is the difference between integer and floating point literals in Java?


Integer literals represent fixed integer values like 900, 12, 400, -222 etc. (with in the integer range).

Whereas, floating point literals represents fractional values i.e. numbers with decimal values like 25.53, 45.66, 58.66 etc. while writing these literals we should use the notation f or F as 25.53.

Example

Live Demo

public class StringExample {
   public static void main(String args[]){
      int num1 = 100;
      float num2 = 30.0f;
      System.out.println("Value of integer:"+num1);
      System.out.println("Value of integer:"+num2);
   }
}

Output

Value of integer:100
Value of integer:30.0

Updated on: 30-Jul-2019

627 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements