This is my code to convert String to ASCII and ASCII to String. I have problem when the user enter text with spaces the all texts didn't convert but if i wrote the text in program the text converted . This is my input "Java is easy"
String str = input.next();
//String str = "Java is easy";
char ch[] = str.toCharArray();
int num[] = new int[str.length()];
for (int i = 0; i < str.length(); i++) {
System.out.print((int)ch[i] + " ");
num[i] = (int)ch[i];
}
System.out.println("");
for (int j = 0; j < str.length(); j++) {
System.out.print((char)num[j]);
}
System.out.println("");
Stringandcharare for UTF-16 code units, one or two of which encode a Unicode codepoint. If you expect the subset of Unicode in common with ASCII, you have to check.