I am a newbie in java. I try to solve UVA using java. But there raise a problem of taking input of string and int at a time. Please help me how to do that???
The inpur is such like...
"donate 1000"
Printable View
I am a newbie in java. I try to solve UVA using java. But there raise a problem of taking input of string and int at a time. Please help me how to do that???
The inpur is such like...
"donate 1000"
Here's the thing: There are about a million ways to do stuff like that in Java (maybe more).
What reference material are you using to learn Java from? Class notes? Textbook? Online tutorials? What?
If you don't have class notes or a textbook, and/or you can't find examples relevant to your requirements, one place to start might be The "Official" Java tutorial site Slog through the fundamentals (don't skip anything). Eventually you will get to a place where it shows examples reading from user input.
If you have already covered fundamentals, then consider a plan that does something like:
- Create a Scanner object with System.in as the argument. (Reference:The Scanner Class)
- Use the Scanner next() method to get user input into a String variable.
- Use the Scanner nextInt() method to get user input into an int variable.
- Do something interesting with the String and int variables.
Cheers!
Z