Monday 29 November 2021

Java: Convert ASCII code to equivalent character

ASCII stands for American Standard Code for Information Interchange, is a character encoding standard for electronic communication.

 

By explicitly casting the integer to a character, we can get the ASCII equivalent of given integer.

 

char ch = (char)i;

 

AsciiCharDemo1.java

package com.sample.app.chars;

public class AsciiCharDemo1 {
	
	private static char printAsciiChar(int i) {
		char ch = (char)i;
		return ch;
	}
	
	public static void main(String args[]) {
		System.out.println("Ascii associated with number 65 is : " + printAsciiChar(65));
	}

}

Output

Ascii associated with number 65 is : A

You may like



 

 

No comments:

Post a Comment