Suppose there is a method called iEvaluate that expects as arguments a double and any number of ints. Here are some examples of a call of this method:
0214: double tResult = iEvaluate(2.7, 25, 2, -5, 42, -10); 0215: System.out.println(tResult); 0216: tResult = iEvaluate(4.2, 42); 0217: System.out.println(tResult); 0218: tResult = iEvaluate(4.2); 0219: System.out.println(tResult);
And here is a possible iEvaluate method:
0221: private static double iEvaluate(double pFactor, int... pValues) 0222: { 0223: int tSum = 0; 0224: for (int tValue : pValues) 0225: tSum += tValue; 0226: return tSum/pFactor; 0227: }
The int... signifies that the remaining arguments are ints. Within the method, this parameter behaves like an array and so the method can use a foreach loop.