However, a method can only return one thing. an int, a String, a FuBar....
But think of it this way...If I can only hand you one thing, what's to say that one thing doesn't hold other things? For example, I could hand you an egg, or I could hand you an egg carton (both times, I give you one thing), but the egg carton may contain 12 (or more) eggs.
So you may be able to create an object that contains your weapon and cWeapon and return that.
Nomaan Butt wrote:if i have understood your problem then,
one way to solve it can be to make weapon and cweapon an array, then when the for loop finishes you can retrieve all the values of these variables.
No need of the strange scenario you mentioned.
I do not see other way that the idea above.
Array object; this should do the work for you.
Ashley Kin wrote:Is that possible? I'm trying to return int weapon and int cWeapon back to the method, but they go back to the for loop first.
Fred's quite right, but it seems to me that you're thinking about this game very procedurally:
There's no doubt that you'll probably arrive at a solution, and it may well work in Java, but it won't be Object-Oriented (which presumably is why you're learning Java).
The same solution could be written in C or COBOL or a whole other raft of languages that don't use objects or classes.
You're getting too bogged down in the "how do I do this?"; what you need to think about more is why - because that is the essence to solving problems, in any language.
One tip for you: Java has a nice little interface called Comparable which may be very helpful. Have a think about a class called Weapon that implements Comparable (so you can compare one Weapon to another).
Alternatively, it has another nice little class called an 'enum', which allows you to create named constants, viz:(I deliberately haven't included any code - and you will need some to solve your problem properly).
Either of these is likely to produce a much more "Java-like" solution than what you're currently trying for; and there are probably other ways too.
The idea is to make objects do the work; not big reams of procedural code.
[EDIT] Having thought about it, the 'enum' solution is probably better, as your particular game is a highly unusual use of Comparable that violates transitivity. It will work for the purposes of the game, but not otherwise.
Can you post a simple example that demonstrates your issue - one that will compile?