How to convert string taken from user into char
Title
Question
Madam/ Sir,
How we convert string taken from user into char. There is no method like Character.parseChar();
Swati Saista.
Java User-Input 08-09 min 30-40 sec
Answers:
To convert string taken from user into a char, you can access specific character within string using indexing ,you can use charAt() method.
Approach:
Scanner sc =new Scanner(System.in);
String userInput = sc.nextLine();
char firstChar = userInput.charAt(0);
//Gets you the first character
Login to add comment