Wednesday, September 18, 2013

Filled Under: , , , , , , , ,

Program to convert characters in to ASCII values

Share
It's very common program to convert entered characters into their ASCII values.
ASCII means American Standard Code For Information Interchange a special numerical values assigned to every type of visible & non-visible characters of computer.
You can find a complete table of ASCII values here..
ASCII Table


And More details about ASCII here!!

This program Converts any Character into its equivalent ASCII value..

Code Box
// program to print ASCII value of any character enter by user

class ascii
{
public static void main(String a[])
{

int i;
char c;

c=a[0].charAt(0); //marker 1
i=c;


System.out.println("Enterd character is:"+a[0]);
System.out.println("    ASCII value is :"+i);

}

}



//marker 1 : charAt() java built in function that capture a character from a string 
               Syntax: char variable=string.charAt(position);
              Where  #string is any string from which you want to to capture the character
                       # position a numerical value or position of character in string

Note: java takes everything as String. In above program a[0] means 0th argument and charAt(0) means its first character always.


To run this program in Command Prompt :

C:\User>javac ascii.java
C:\User>java ascii h


Out Put: 
Entered character is: h
ASCII value is : 104


Try it!!

If you have any query than feel free to write me. Your are also welcome for any advice & suggestions
make learning more better..

0 comments:

Post a Comment