To print ascii value of a character this is the the simplest way to change the type a character. Here in the example given below we will select character from a given string and change their type to integer that will be their ascii value.
Method charAt() of String class is used to select character in the given string on basis of given index value as argument.
|
public class GetAsciiValue { public static void main(String[] args) { String s = "Java"; for (int i=0; i<s.length();i++) System.out.println("ASCII value of: "+s.charAt(i) + " is:"+ (int)s.charAt(i) ); } } |
Output will be displayed as:

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.
Ask Questions? Discuss: Get Ascii Value View All Comments
Post your Comment