Click here to Skip to main content
14,265,813 members
Rate this:
Please Sign up or sign in to vote.
See more:
Java code to convert char ti ASCII

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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100