convert int to char in java

 9. convert int to char in java


package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// write your code here
int a;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
a=sc.nextInt();
char b = (char)a;/*there might be a loss of data while converting from int to car.
so ,we are using (char) to specify that a should be converted to
character*/
System.out.println(b);
}
}
output:-
Enter a number : 
80
P

Process finished with exit code 0

Comments

Popular posts from this blog

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

Phone Dictionary Application in c

BITWISE OPERATOR