The Artima Developer Community
Sponsored Link

Java Answers Forum
char problem

4 replies on 1 page. Most recent reply: Sep 18, 2003 3:54 AM by gratiartis

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
shon

Posts: 42
Nickname: shon
Registered: Apr, 2003

char problem Posted: Sep 17, 2003 6:51 AM
Reply to this message Reply
Advertisement
can anyone tell me how to convert numbers to char ??
for ex:

integer 1 to char '1';
thanks for answering.


gratiartis

Posts: 8
Nickname: gratiartis
Registered: Sep, 2003

Re: char problem Posted: Sep 17, 2003 10:20 AM
Reply to this message Reply
This may not be appropriate since it depends on what you're trying to do, but it can be done as follows:

    int zeroValue = new Character( '0' ).charValue() ;
    char three = (char)( 3 + zeroValue ) ;
 
    System.out.println( "zeroValue=" + zeroValue ) ;
    System.out.println( "three=" + three ) ;


Some may want to flog me for this tip, but I think it works fairly reliably ;)

shon

Posts: 42
Nickname: shon
Registered: Apr, 2003

Re: char problem Posted: Sep 17, 2003 8:30 PM
Reply to this message Reply
thanks

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: char problem Posted: Sep 17, 2003 9:28 PM
Reply to this message Reply
// assuming base 10
char three = Character.forDigit(3, 10);

gratiartis

Posts: 8
Nickname: gratiartis
Registered: Sep, 2003

Re: char problem Posted: Sep 18, 2003 3:54 AM
Reply to this message Reply
I knew there must be a simpler way of doing it!
:)

Flat View: This topic has 4 replies on 1 page
Topic: Passing array of objects into methods Previous Topic   Next Topic Topic: Yahoo games

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use