How to turn each character of a string into its ASCII character code in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java programming";
      
        for (int i = 0; i < s.length(); i++) {
            System.out.printf("%d ", (byte)s.charAt(i));
        }
    }
}



/*
run:

106 97 118 97 32 112 114 111 103 114 97 109 109 105 110 103 

*/

 



answered Apr 2, 2021 by avibootz
...