- #1
bomba923
- 763
- 0
Is there a way to convert a character representation of an integer into an integer (with integer representation )?
*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? Shorter than typing out:
" Integer.parseInt(String.valueOf(nmbr.charAt(pst))) " ?
*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? Shorter than typing out:
" Integer.parseInt(String.valueOf(nmbr.charAt(pst))) " ?