0
Scanner can't convert to String
So this I found interesting. I want my input to be a string I can work with, but I get errors when working with it. So I thought it isn't properly a string, hence it can't be worked with. On attempt to make it legit a string, it says no. SoloLearn says this is the most popular form of input, is there something else? class In { public static void main(String[ ] args) { System.out.println ("What is your name?"); Scanner myVar = new Scanner(System.in); // String name = myVar; System.out.println(myVar.nextLine()); } }
3 Answers
+ 4
The Scanner Object has functions for getting input, it isn't the input itself
+ 4
I know your problem is solved but here is the doc for the Scanner class and it contains all the methods that can be used on a Scanner object... Get used to using the Java (or any language) docs. They are an invaluable source of information.
https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html