How to convert int to char in Java
Example:
Input: num=65
Output: A
Approach: 1:
Java
public class IntToChar {public static void main(String[] args) {int num = 65;char ch = numToChar(num);System.out.println("char is " + ch);}private static char numToChar(int num) {return (char) num;}}
Approach : 2:
Java
public class IntToChar {public static void main(String[] args) {int num = 1;char ch = numToChar(num);System.out.println("char is " + ch);}private static char numToChar(int num) {return (char)(num+'0');}}
No comments:
Post a Comment