+ 11

In java why Systems.out.println(1_0 == 10); gives true ?

5th Jul 2019, 4:28 AM
Lohith Viswa
Lohith Viswa - avatar
12 odpowiedzi
+ 27
Because 1_0 is 10. Underscore just separates digits so you can read numbers more easily. x= 1000000 is not so easy to read, x= 1_000_000 now you can easily see that x is one million. Here you will find more information (scroll all the way down) https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
5th Jul 2019, 4:42 AM
voja
voja - avatar
+ 9
0_9 gives compile time error. If you put 0 in front of a number, then you are using Octal number system 01=1 02=2 07=7 010=8 011=9...
5th Jul 2019, 6:08 AM
voja
voja - avatar
+ 7
I just learnt that underscore sign is set to improve readability from _voja_
5th Jul 2019, 5:33 AM
E∆SI🇳🇬🤖
E∆SI🇳🇬🤖 - avatar
+ 6
voja and 10 are both readable without underscores. Just saying.
5th Jul 2019, 5:48 AM
Sonic
Sonic - avatar
+ 6
I dont tink so..., 09 is not an integer value
5th Jul 2019, 5:59 AM
E∆SI🇳🇬🤖
E∆SI🇳🇬🤖 - avatar
+ 5
Sonic yah But dats a good system
5th Jul 2019, 5:51 AM
E∆SI🇳🇬🤖
E∆SI🇳🇬🤖 - avatar
+ 5
Is 0_9==9 ?
5th Jul 2019, 5:56 AM
Lohith Viswa
Lohith Viswa - avatar
+ 5
Using Underscore Characters in Numeric Literals In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example. to separate groups of digits in numeric literals, which can improve the readability of your code. For instance, if your code contains numbers with many digits, you can use an underscore character to separate digits in groups of three, similar to how you would use a punctuation mark like a comma, or a space, as a separator.
5th Jul 2019, 5:23 PM
Rotrick Lijo
Rotrick Lijo - avatar
+ 4
Y if we give 09 to a number it takes as 9
5th Jul 2019, 6:02 AM
Lohith Viswa
Lohith Viswa - avatar
+ 4
Tqsm
5th Jul 2019, 2:22 PM
Lohith Viswa
Lohith Viswa - avatar
+ 4
Underscore just separates doesn't change the way the number is written😊
5th Jul 2019, 5:37 PM
John Dhinakar
John Dhinakar - avatar
+ 3
Hey,Hii there.underscore is mainly used in the variable naming as we can name the variable with mix of numbers and alphabet by using this underscore. BUT IT WONT HAVE ANY EFFECT ON CONSTANTS.. Ex: Customer_id=12 print(200=20_0) HOPE IT HELPS.. HAPPY CODING😀😀
6th Jul 2019, 6:33 PM
Dheeraj
Dheeraj - avatar