uyusuk uyusuk - 27 days ago 5
Java Question

How do I get both integer and string from the user

How can I get this when the user enters a mixed input.

We use this for integer:

Scanner input = new Scanner(System.in);
int number = input.nextInt();


We use this for String:

Scanner input = new Scanner(System.in);
String name = input.next();


How can we use both of them at once?
For example: password123
How can i save it?

I think I should use the java generic class.I searched for Java Gneric, but I did not understand.

Thank you.

Answer

password123 is a string, that happens to contain numbers.

So using this should work:

Scanner input = new Scanner(System.in);
String name = input.next();