- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Using underscore in Numeric Literals in Java
Followig is the code showing how to use underscore in numeric literals in Java −
Example
public class Demo{ public static void main (String[] args) throws java.lang.Exception{ int my_num_1 = 6_78_00_120; System.out.println("The number is : " + my_num_1); long my_num_2 = 2_00_11_001; System.out.println("The number is : " + my_num_2); float my_num_3 = 4.01_981F; System.out.println("The number is : " + my_num_3); double my_num_4 = 12.89_46_061; System.out.println("The number is : " + my_num_4); } }
Output
The number is : 67800120 The number is : 20011001 The number is : 4.01981 The number is : 12.8946061
A class named Demo contains the main function which uses various formats of integer, long, floating point values and double values to display data with the help of underscotres. This is assigned to a variable each, that is printed on the console.
- Related Articles
- Literals in Java programming
- Boolean Literals in Java
- Vertically align numeric values in Java using Formatter
- What are literals in Java?
- What are Boolean literals in Java?
- What is the difference between character literals and string literals in Java?
- Underscore(_) in Python
- Using MySQL IN() for some column values with underscore
- Define integer literals as octal values in Java
- Java Numeric Promotion in Conditional Expression
- What is the use of underscore keyword in Java 9?
- Integer literals vs Floating point literals in C#
- Literals in C#
- Sorting an array of literals using quick sort in JavaScript
- What are the rules about using an underscore in a C++ identifier?

Advertisements