0
How to convert a user input word to string which is read using scanner class?
3 Réponses
+ 2
the next method already returns it as a string
+ 2
To extend Gershon Fos's answer with code:
Scanner sc = new Scanner(System.in);
String userInput = sc.next();
This code asks for user input, then saves the input as string in variable userInput.
0
there various ways Java parses values, you can use these methods to cast from on type to another, when this is not possible, Java raises a classcastexception such as int hello_world = sc.next parseInt("hello world") would throw an exception but to answer your question all you need to do to statically cast objects, you can use Javas parse methods to cast types, look at parseString()