Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java code to convert char ti ASCII

Java
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;
          System.out.println("ASCII OF "+c +" = " + j + ".");
       }
     }
  }


I know how to convert character to ASCII but I am struggling to do vice-versa
How can we convert ASCII number to its character equivalent.

what exactly I want is if input is :- 657578104 ...likewise
Then output should be :- AKNh ...likewise
Posted
Updated 8-Feb-12 20:29pm
v5
Comments
TorstenH. 9-Feb-12 2:29am    
your example is quite ok, now turn it around and you'll have the homework done.

1 solution

You can use (char)i. There is no ASCII to Char conversion, it is int to char.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900