I'm trying to get a character from user as input from the keyboard, I couldn't able to find a way to read character from keyboard and store it in character array. Kindly help me to find a solution.
Asked
Active
Viewed 63 times
3 Answers
1
You have to use the Java Scanner class to read in the next line and get the first character of that line. Refer to this StackOverflow Question
-
HI Mark,I tried that method to get the first character from the input string but it won't works... – Mano Jun 08 '15 at 04:02
-
Could you post your code so we can see what's wrong? – Mark Jun 08 '15 at 04:18
-
If you've a similar question, then you should flag this question here as a duplicate, instead of answering it again. – Tom Jun 08 '15 at 06:16
0
You can use Scanner
and the findInLine
method:
Scanner inputTaker = new Scanner(System.in);
String input = inputTaker.nextLine();
Scanner scanner = new Scanner(input);
char someCharacter = scanner.findInLine(".").charAt(0);
// Do something with character
More here: Scanner method to get a char

Community
- 1
- 1

nonamorando
- 1,556
- 2
- 14
- 33
-
-
If you've a similar question, then you should flag this question here as a duplicate, instead of answering it again. – Tom Jun 08 '15 at 06:16
-1
I think there is no need of creating a new instance once again for the Scanner class.
Scanner inputLine = new Scanner(System.in);
char[] charArray = inputLine.toCharArray();
System.out.println(charArray[0]);// 0 is used for example and you can use it based on your requirement.

SASIKUMAR SENTHILNATHAN
- 473
- 2
- 4
- 20