Friday, April 5, 2019

Using Underscore in Numeric Literals Java

This is new Java feature introduced in Java 7 just to improve the readability of codes like we can use an Underscore character to separate digits in group of three,similar to how we would use a punctuation Mark like comma, or a space,as a seperatot.

For example; 

public class UnderscoreInLiteral
{
  public static void main(String args[])
  {
      int num = 1_00_00_000;
      System.out.println("Num:",num);
  
    long num1 = 1_00_00_000;
    System.out.println("Num",num1);
   }

}

Output:

10000000
10000000

No comments: