jhoanne jhoanne - 2 months ago 10
Java Question

How can I display the desired value in ASCII code inputted by me?

I need Java code. Please help me. Example: when I enter the number in ASCII

0 the output will be nul
1 for soh
2 for stx until it reaches the max number of ASCII.


Please I need it now.

Consider this code. It outputs an ASCII number. How can I reverse it?

String test = "ABCD";
for ( int i = 0; i < test.length(); ++i ) {
char c = test.charAt( i );
int j = (int) c;
System.out.println(j);
}

Answer
import java.io.*;
import java.lang.*;
    public class CharToASCII{
        public static void main(String args[]) throws IOException{
          BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Enter the char:");
          String str = buff.readLine();
          for ( int i = 0; i < str.length(); ++i ){
            char c = str.charAt(i);
            int j = (int) c;// your work is done here
            System.out.println("ASCII OF "+c +" = " + j + ".");
            }
        }
      }