• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Numeric and Integer value? Same?

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A question in JQ+ asks what will the foll stmt return?
i = Character.getNumericValue(ch);
Ans :10
This returns Numeric Value which is 10 for 'a'.
But Integer Value of 'a' is 97...
Then what is this???
Sonir
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a is just 10 in hexidecimal.
Character.getNumericValue(char) returns the decimal equivalent of the character that represents a numeric digit.
Some examples...
Character.getNumericValue('1') returns the number 1
Character.getNumericValue('5') returns the number 5
Character.getNumericValue('F') returns the number 15.
Hope this helps.

Rob
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sonir, the value returned to you is the hexidecimal value of 'a' which is 10
likewise the hexidecimal value of 'f' will be 15
Try this code yourself, with ch set to one of the following characters '9','a','d','f'
<pre>
class Test {
public static void main(String[] arg) {
char ch = 'f';
int i = Character.getNumericValue(ch);
System.out.println(i);
ch = '9';
i = Character.getNumericValue(ch);
System.out.println(i);
}
}
</pre>
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic