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 and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Longest prefix matching - A Trie based solution in Java
- Java Program to Display Numbers and Sum of First N Natural Numbers
- How to Initialize and Compare Strings in Java?
- Printing Integer between Strings in Java
- Swap two Strings without using third user defined variable in Java
- Compare two strings lexicographically in Java
- Check whether two Strings are Anagram of each other using HashMap in Java
- Compare two Strings in Java
- Strings in Java
- Compact Strings in Java 9 with Examples
- How to Match Regions in Strings in Java?
- Java Program to Write an Array of Strings to the Output Console
- Java Program to Print all the Strings that Match a Given Pattern from a File
- Program to add and Subtract Complex Numbers using Class in Java
- Different Ways to Generate String by using Characters and Numbers in Java
- Print even and odd numbers in increasing order using two threads in Java
- Print all possible strings of length k that can be formed from a set of n characters
- Find all palindromic sub-strings of a given string | Set 2
- Number of character corrections in the given strings to make them equal
- CompileTime Vs RunTime Resolution of Strings