How to get character code (ASCII and Unicode) in Java

4 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'a';
        
        System.out.println((int)ch); 
    }
}




/*
run:

97

*/

 



answered Jan 21, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'a';
        
        int char_code = (int)ch;
        
        System.out.println(char_code); 
    }
}




/*
run:

97

*/

 



answered Jan 21, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'π';

        int char_code = (int)ch;
        
        System.out.println(char_code); 
    }
}




/*
run:

960

*/

 



answered Jan 21, 2023 by avibootz
0 votes
class Main {
    public static void main(String[] args) {
        // Unicode
        String s = "é";
        
        int cp = s.codePointAt(0);
        System.out.println(cp);

    }
}



/*
run:

233

*/

 



answered Apr 15 by avibootz
...