How to do it without char c = scanner.next().charAt(0) as I didn't learn how to use 'At' and read function invokes only one character while I want it to read the entire line.
Asked
Active
Viewed 82 times
-3
-
1Define "invoke a character". Make your question clear. If you want to read an entire line from a Scanner, then call nextLine(). The javadoc is your friend. – JB Nizet Apr 01 '17 at 15:50
-
Explain what you are trying to do. – Noel Murphy Apr 01 '17 at 15:51
-
If you want to read a **line** why don't you use `nextLine()` then? – QBrute Apr 01 '17 at 15:56
-
guys nextLine() is for a string and invoke a character means that the user has to give the character – Ruchir Apr 02 '17 at 12:09
-
By "invoke" do you mean "Get a character from user input"? – slim Apr 02 '17 at 18:18
1 Answers
0
One of the approaches can be: read the line using nextLine()
and store it in a String
and then use charAt()
something like:
String line = reader.nextLine();
char c = line.charAt(0);

MohamedSanaulla
- 6,112
- 5
- 28
- 45