title: Printing out student averages with file input using string tokenizer and scanner
body: <p>I am trying to get the averages of values in a text file. The content of the file is:</p>
  
  <blockquote>
    <p>Agnes 56 82 95 100 68 52 <br/>
      Bufford 87 92 97 100 96 85 93 77 98 86 <br/>
      Julie 99 100 100 89 96 100 92 99 68 <br/>
      Alice 40 36 85 16 0 22 72 <br/>
      Bobby 100 98 92 86 88</p>
  </blockquote>
  
  <p>I have to skip the names, and try to sum the values of the integers of each line. The ouput should be something like this:</p>
  
  <blockquote>
    <p>Agnes, average = 76 <br/>
      Bufford, average = 91 <br/>
      Julie, average = 94 <br/>
      Alice, average = 39 <br/>
      Bobby, average = 93</p>
  </blockquote>
  
  <p>My problem is that i am unable to sum the values (using sum+=sc1.nextInt()). I also cant count the number of tokens of just the integers. For example, for the first line I need countTokens to equal 6, but i get 7, even after I skip the name.</p>
  
  <pre><code>import java.io.*; 
  import java.util.*; 
  public class studentAverages
  {
  public static void main() throws IOException
  {
      Scanner sf = new Scanner(new File("C:\\temp_Name\\StudentScores.in"));
      int maxIndex = -1; 
      String text[] = new String[100]; 
      while(sf.hasNext( ))
      {
          maxIndex++;
          text[maxIndex] = sf.nextLine();
      }
      sf.close();
  
      int sum=0;
      int avg=0;
      int divisor=0;
      for (int i=0;i&lt;=maxIndex; i++)
      {
          StringTokenizer sc= new StringTokenizer(text[i]);
          Scanner sc1= new Scanner (text[i]);
  
          while (sc1.hasNext())
          {
              sc1.useDelimiter(" ");
              sc1.skip("\\D*");                
              System.out.print(sc1.nextInt());
              System.out.println(sc1.nextLine());
              sum+=sc1.nextInt(); // trying to sum all the numbers in each line, tried putting this line everywhere
              avg=sum/divisor;
              break;
          }            
          System.out.println(avg);
          while (sc.hasMoreTokens())
          {         
              divisor=sc.countTokens()-1; //Not able to count tokens of just the numbers, thats why I am using -1 
              //System.out.println(divisor);
              break;
          }
      }
      //this is for the output 
      /*for (int i=0; i&lt;=maxIndex; i++)
      {
          String theNames="";
          Scanner sc= new Scanner (text[i]);
          theNames=sc.findInLine("\\w*");
          System.out.println(theNames + ", average = ");
      }*/
  }
  }
  </code></pre>