Page 1 of 1

cannot find symbol

Posted: Sun Aug 19, 2012 7:29 am
by jon80
Any idea why this won't compile please?

Code: Select all

/**
 * Java Program which tries to implement variable argument method using
 * method overloading. This started get clumsy once number of parameter exceeds
 * five.
 */
class  VarargsExample{

  /*
   * @return multiplication of all numbers in array
   */
  public int multiply(int[] numbers){
    int result = 1;

    for(int number: numbers){
      result= result*number;
    }

    return result;
  }
}

public class VarargsExampleTest
{
	public static void main (String... args)
	{
		int[] a = new int[] {1,3,2,4,5};
		VarargsExample v = new VarargsExample();
		int[] results = new int[5];
		for (int i = 0;  i < results.length; i++)
		{results[i] = v.multiply[a];}
		for (int i = 0;  i < results.length; i++)
		{System.out.println(results[i]);}
	}
}
/*
Read more: http://javarevisited.blogspot.com/2011/09/variable-argument-in-java5-varargs.html#ixzz23yTFsnIG
*/