There are two things you could do.  One is to instantiate an object of type Ex6 in your app:
 
  Ex6 ex = new Ex6();
  ...
  int answer = ex.addint( table );
 
or make addint a static method.  The latter would seem the most logical as the method does not reference instance data.  There is also a small modification (if I may suggest) that will make it more robust -- it will handle empty arrays:
 
  public static int addint( int [] array) {
    int sum = 0;
    for (int p = 0; p < array.length; p++) {
      sum += array[p];
    }
    return sum;
  }
 
In this case, of course, you would leave the calling statement as is: int answer = Ex6.addint( table );
 
Tomm
--
Be careful when reading health books.  You
might die of a misprint. - Mark Twain
----- Original Message -----
To: jdjlist
Sent: Saturday, February 08, 2003 5:23 AM
Subject: [jdjlist] an error that I am getting and don't understand ????

Hi list,
 
The program that is involved in this case, is a very small one.
It is to do with arrays which have been passed as parameters to methods -- my current topic.
I am getting errors that I don't understand why I am getting them.
Can someone help ?
 
==================================================================
==================================================================
public class Ex6 {
   
   public int addint (int [] array)
   {
     
     int sum = array[0];
     
    for (int p = 1; p < array.length; p++)
    {
     sum += array[p];
     
      }//END OF for LOOP
     
    return sum; 
     
   }// end of method
  
  
}//END OF CLASS
 
==================================================================
==================================================================
 
import Ex6;
public class Ex {

   public static void main (String [] args)
   {
 
//Ex6.5 as a class name does not work
 
     int [] table = {3, 7, 9, 2};
   
   
   
    int answer = Ex6.addint(table);
  
  
  
}//End of main method
}//End of class
---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to