saving . . . saved How to convert string taken from user into char has been deleted. How to convert string taken from user into char has been hidden .
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 17-10-23, 4:41 p.m. swatisaista30@gmail.com

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
19-10-23, 2:15 p.m. a_jit_77
Thanks.
23-11-23, 2:14 p.m. swatisaista30@gmail.com

Login to add comment


Log-in to answer to this question.