0

Numeric value of character code coach

How to solve this problem in correct way? import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); char a = read.next().charAt(0); //your code goes here int b = (int) a; System.out.println(b); }

31st Oct 2020, 5:12 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar
2 Réponses
+ 4
Scanner class is used to take input. And this inputted character value is stored in variable "a". It is then assigned to another integer variable "b" through explicit type casting i.e. (int) a =>means a character is explicitly type casted to an integer. And then it is printed.
31st Oct 2020, 5:19 AM
Alphin K Sajan
Alphin K Sajan - avatar
0
Yeah, but test cases don't accept.
31st Oct 2020, 5:21 AM
Yaroslav Yatsyk
Yaroslav Yatsyk - avatar