Collective value of integers...efficient way of checking?

im trying to write a function that checks value of eleven incoming integers to see if they are under 40.0

is it just a matter of if (int1 ++ int2 ++ int3....) < 40

{

return true;

}

or is there a more efficent way of doing it

here is my method

public void assumeValue(goalkeeper,right_full,centreback1,centreback2,left_full,winger_left,centremid1,centremid2,winger_right,striker1,striker2)

{

int goal = Integer.parseInt(goalkeeper);

int right = Integer.parseInt(right_full);

int cent_1 = Integer.parseInt(centreback1);

int cent_2 = Integer.parseInt(centreback2);

int left = Integer.parseInt(left_full);

int wingleft = Integer.parseInt(winger_left);

int mid_1 = Integer.parseInt(centremid1);

int mid_2 = Integer.parseInt(centremid2);

int wingright = Integer.parseInt(winger_right);

int goal_1 = Integer.parseInt(striker1);

int goal_2 = Integer.parseInt(striker2);

//if statement to validate if collective value is under 40 goes here

}

[1082 byte] By [Styx218a] at [2007-11-27 3:42:35]
# 1

Yes there is - don't pass that many parameters. Instead pass in a Collection ... simplest if you know the total number of argument - which I believe you do in this case - is an array.

ex:

public boolean myMethod(Integer[] allPlayersScores) throws NumberFormatException {

int totalScore = 0;

for ( int i = 0; i < allPlayersScores.length; i++ ) {

totalScore += Integer.parseInt(allPlayersScores[i]);

if (totalScore > 40) break;

}

return( totalScore > 40 ? true : false );

}

abillconsla at 2007-7-12 8:46:11 > top of Java-index,Java Essentials,New To Java...
# 2
> Integer.parseInt(allPlayersScores)What's being passed in, anyway? Strings or int/Integer?
DrLaszloJamfa at 2007-7-12 8:46:11 > top of Java-index,Java Essentials,New To Java...
# 3
Passing in strings. then parsing to get integer vaue form them..So create an array,add arguments to array, pass array to my method and then check if value is under 40....that should do it thanks for your help guys!!
Styx218a at 2007-7-12 8:46:11 > top of Java-index,Java Essentials,New To Java...
# 4

> > Integer.parseInt(allPlayersScores)

>

> What's being passed in, anyway? Strings or

> int/Integer?

Uff ... in my haste I made a waste. Anyway, thanks for pointing that out. Yes, if it's Integers being passed in, then you want totalScore += allPlayersScores.intValue(); ... and you can do away with the NFE throw.

abillconsla at 2007-7-12 8:46:11 > top of Java-index,Java Essentials,New To Java...
# 5
You are welcome, thank you back.
abillconsla at 2007-7-12 8:46:11 > top of Java-index,Java Essentials,New To Java...