Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,167 questions

40,724 answers

573 users

How to turn each character of a string into its ASCII character code and join them together in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java programming";
        String ascii = "";
       
        for (int i = 0; i < s.length(); i++) {
            int asciicode = (byte)s.charAt(i);
            System.out.printf("%d ", asciicode);
            ascii = ascii + asciicode;
            
        }
        System.out.println("\n" + ascii);
    }
}
 
 
 
/*
run:
 
106 97 118 97 32 112 114 111 103 114 97 109 109 105 110 103 
10697118973211211411110311497109109105110103
 
*/

 





answered Apr 2, 2021 by avibootz
...