How to convert character to ASCII numeric value in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        char character = 'a';    
        
        int ascii = (int)character;
        
        System.out.println(ascii);
    }
}
 
 
 
/*
run:
 
97
 
*/

 



answered Apr 2, 2021 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char character = 'b';    
        
        byte ascii = (byte)character;
        
        System.out.println(ascii);
    }
}
 
 
 
/*
run:
 
98
 
*/

 



answered Apr 2, 2021 by avibootz

Related questions

1 answer 110 views
1 answer 179 views
1 answer 128 views
...