Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Quick quick Java question

  1. Sep 30, 2005 #1
    :redface: Is there a way to convert a character representation of an integer into an integer (with integer representation :rolleyes:)?
    *for example (I'll add 8 to a certain digit in an integer),

    String nmbr; //where I enter a number
    int pst; //an integer representing the position of that digit in the number

    System.out.println( nmbr.charAt(pst) + 8 );

    Obviously, I cannot add a character and an integer. Thus, I change to:

    System.out.println( Integer.parseInt(String.valueOf(nmbr.charAt(pst))) + 8 );

    and it works, no compiling errors.

    *However, is there a shorter way of converting a character representation of an integer to...well, an integer? :frown: Shorter than typing out:

    " Integer.parseInt(String.valueOf(nmbr.charAt(pst))) " ?
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted