| 
    
        |  | Re: Checking the arrays then adding and averaging... | Posted: Dec 2, 2004 2:12 AM |  |  
        | Hi Alan, 
 in couple of places where u r trying to read the userValues the sqaurebrace i squarebraceclose are missing. U need to add them after userValues in the for loop and excetpion handling part. Then the code will work fine. There is some problem with artima editor, its not taking squarebraceopen i squarebraceclose \[i\]
 
 public class FindAverage {
 public static void main(String args[]) {
 String[] userValues = {"abc", "xyz", "1", "34", "45", "jkl"};
 int totalSum = 0;
 int elementCount = 0;
 for (int i = 0; i < userValues.length; i ++) {
 try {
 totalSum += (Integer.parseInt(userValues\[i\]));
 elementCount++;
 } catch (NumberFormatException nfe) {
 System.out.println(userValues\[i\] + " is not an integer.");
 }
 }
 System.out.println("Sum = " + totalSum);
 System.out.println("Elements = " + elementCount);
 float avg = totalSum/elementCount;
 System.out.println("Average = " + avg);
 }
 }
 
         |  |