Numbers in Java (With 0 Prefix and with Strings)
Consider the following Java program.
The reason for above output is, when a 0 is prefixed the value is considered octal, since 12 in octal is 10 in decimal, the result is 10. Similarly, if i = 0112, result will be 74 (in decimal). This behavior is same as C/C++ (see this).
Java takes the numbers before the strings are introduced as int and once the string literals are introduced, all the following numbers are considered as strings.
This article is contributed by Hiresh Trivedi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.