A Java Question
Results 1 to 7 of 7

Thread: A Java Question

  1. #1
    Senior Member Falcon21's Avatar
    Join Date
    Dec 2002
    Location
    Singapore
    Posts
    252

    A Java Question

    Hello, I have a newbie question here. How do I convert the char and String data type to an integer in Java so that I can perform arithmetic operation?

    Thanks.


  2. #2
    Senior Member
    Join Date
    Jun 2003
    Posts
    772
    like this?

    char crap = 'a';
    int othercrap = (int)crap;

    othercrap would have the ascii code value of 'a' then.
    The above sentences are produced by the propaganda and indoctrination of people manipulating my mind since 1987, hence, I cannot be held responsible for this post\'s content - me

    www.elhalf.com

  3. #3
    Senior Member
    Join Date
    Jan 2002
    Posts
    1,207
    If you want to decode them in decimal, use the Integer.parseInt() method (IIRC)

    something like

    Code:
      String mystr = "42";
      int theAnswer = Integer.parseInt(mystr);
    Slarty

  4. #4
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    I strongly recommend keeping a link on hand to the api documentation on http://java.sun.com . A quick run through there before coming here would probably save you time.
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  5. #5
    Senior Member
    Join Date
    May 2003
    Posts
    226
    Integer.parseInt will do the job nice

  6. #6
    Senior Member Falcon21's Avatar
    Join Date
    Dec 2002
    Location
    Singapore
    Posts
    252
    Thanks, Integer.parseInt works.

  7. #7
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    Will Integer.parseInt convert the String datatype to int? :P
    j/k, I just thought it was funny that it was mentioned 3 times. the java API owns j00.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides