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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 10-Jan-2018 05:52:39
Advertisements