uyusuk uyusuk - 1 year ago 66
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(;
int number = input.nextInt();

We use this for String:

Scanner input = new Scanner(;
String name =;

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 Source

password123 is a string, that happens to contain numbers.

So using this should work:

Scanner input = new Scanner(;
String name =;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download