Home Java Java-conversion Convert a Character into the ASCII Format



Convert a Character into the ASCII Format
Posted on: June 15, 2007 at 12:00 AM
In this section, you will learn to convert a character data into the ASCII format.

Convert a Character into the ASCII Format

     

In this section, you will learn to convert a character data into the ASCII format. The java.lang package provides the functionality to convert the  character data into the ASCII format

Description of Code:

The following program helps in converting a character data into ASCII. Create a class "CharToASCII". This program takes a character at the console . It fragments the given string according to its positions with the help of charAt() method. This method returns the character at the specified index. Type casting ((int) c) is done to convert the character into an ASCII. 

Here is the code of this program:

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

Download this program:

Output of this program.

C:\corejava>java CharToASCII
Enter the char:
A
ASCII OF A = 65.
C:\corejava>

Related Tags for Convert a Character into the ASCII Format:
javacideclassormdataformfunctionconsoleconvertfuniohelpformatcharasciivichartoleintthisidpackagefunctionalcharactercreateforunccteprogramtoramcilaneitdesliartinrmconvertingasmntpsjpackclesfuncageintoproackssoatpacrackishallfolloweafunctionalityaractconsrtwingvassthavpronogrolo


More Tutorials from this section

Ask Questions?    Discuss: Convert a Character into the ASCII Format   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.