Hello, using the console I want read two or more variables in the same line.
Exemple: "John 9" or "Michelle 8".
After assign 'John' to String variable and '9' to int variable. without strings treatment
can anybody help me? thanks
Printable View
Hello, using the console I want read two or more variables in the same line.
Exemple: "John 9" or "Michelle 8".
After assign 'John' to String variable and '9' to int variable. without strings treatment
can anybody help me? thanks
Look into String.split().
no, It doesn't help
Can you show us what you've done with the split().
I didn't use split. My problem is at reading.
I thought you were already reading "John 9" or "Michelle 8". Use Console.readLine() to read those strings. Then use String.split() on them.
Yes, I understood what you want to do. Reading something like "John 9", you need to separate into "John" and "9". String (Java Platform SE 6) Does the same. Have you read it?
Another approach is to use the Scanner class. It has methods that will read a word from the console and it will read a word and convert it to an int. The two can be typed on the same line before pressing Enter