• Register

Java Translate characteracter to integer

We can alter character  to integer  using many techniques. If we straightly allot character var to integer, it will yield ASCII number of given character.

If character var holds integer digit, we can catch the integer number by invocating  Character.getNumericValue(character) technique. Otherwise, we can use Str.valueOf(character) technique.

1)   Character to integer Method

Get ASCII number

Let us perceive the most simple code to alter character to integer.

1.    public class CharacterToInteger{  

2.    public static void main(Str args[]){  

3.    char character1='a';  

4.    char character2='1';  

5.    int ab=character1;  

6.    int bc=character2;  

7.    System.out.printegerln(ab);  

8.    System.out.printegerln(bc);  

9.    }}  

Try it

Outcome:

97

49

2)  Character to integer Method

 Character.getNumericValue()

Let us perceive the simplest code to alter character to integer in java using Character.getNumericValue(character) technique which returns an integer value.

getNumericValue(character) yields the integer value that the specified Unicode char.

Try it

1.    public class CharacterToIntegeregeregerMethod2{  

2.    public static void main(Str args[]){  

3.    character char1='1';  

4.    int abc=Char.getNumericValue(char1);  

5.    System.out.println(abc);  

6.    }}  

 

Outcome:

1

3)  Java character to integer Method

Str.valueOf()

Let's see another Method which returns integer value of definite character value using Str.valueOf(character) technique.

The java str valueOf() technique alter dissimilar kinds of values integer str. Using str valueOf() technique, you can alter integer to str, long to str.

1.    public class CharacterToIntegeregeregerMethod3{  

2.    public static void main(Str args[]){  

3.    character char1='1';  

4.    integeregereger abc=Integeregeregereger.parseIntegeregereger(Str.valueOf(char1));  

5.    System.out.println(abc);  

6.    }}  

Try it

Outcome:

1

 

2,760 points
7 4