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"
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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