• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

forDigit ()?????

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what does the following forDigit() method return.
static char forDigit(int num,int radix)
According to what i have read it returns the digit character associated with the value of num.
The following is the code:
int num=49;
char ch2=Character.forDigit(num,10);
System.out.println(ch2);
According to me, 1 should be the output but nothing is getting printed,though no compile error is generated.could anyone tell what is wrong with this code?
thanx in advance.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello i found this piece of info in JLS .Hope this helps.
"
20.5.24 public static char forDigit(int digit, int radix)
Returns a character that represents the given digit in the specified radix. If the value of radix is not a valid radix, or the value of digit is not a valid digit in
the specified radix, the null character '\u0000' is returned.
A radix is valid if and only if its value is not less than Character.MIN_RADIX (2) and not greater than Character.MAX_RADIX (36).
"A digit is valid if and only if it is nonnegative and less than the radix."
If the digit is less than 10, then the character value '0'+digit is returned; otherwise, 'a'+digit-10 is returned. Thus, the digits produced by forDigit, in
increasing order of value, are the ASCII characters:
0123456789abcdefghijklmnopqrstuvwxyz "
Since a digit is valid if and only if it is non-negative and less than radix,in your case 49 is greater than 10 and hence is an invalid digit and a null character is returned.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic