4 Replies Latest reply on Mar 9, 2007 10:14 PM by 807606

    String Tokenizer

    807606
      I am having trouble using the stringtokenizer to extract the numbers from my file and then find the max and average of them. I kept on getting errors so I have gone back to where it prints out the lines of my file and there are no errors.

      Here is the code I have so far:

      import java.io.*;
      import java.util.StringTokenizer;

      class Exam_1 {

      public static void main (String[] args) throws IOException {

      Exam_1 d = new Exam_1();
      d.readMyFile();
      }

      //Read MyFile

      void readMyFile() {

      String reader = null;
      int recCount = 0;
      try { FileReader fr = new FileReader("Exam_1_File.java");
      BufferedReader br = new BufferedReader(fr);
      reader = new String();
      while ((reader = br.readLine()) != null) {
      recCount++; System.out.println(recCount + ": " + reader);
      }
      }
      catch (IOException e) {
      // catch possible io errors from readLine()
      System.out.println("Uh oh, got an IOException error!");
      e.printStackTrace();
      }



      } // end of readMyFile(

      } // end of class

      Here is my file it is reading from:

      import java.text.*;

      public class Exam_1_File{

      public static void main(String[] args) {
      double a = 16.54;
      double b = 234.56;
      double c = 143.65;
      double d = 1.45;
      double e = 97.43;

      }
      }

      If anybody can help steer me in the right direction I would really appreciate it.

      Thanks
        • 1. Re: String Tokenizer
          796447
          I see no usage of StringTokenizer anywhere in that application. So there's no helping you yet really. Surely you're not just asking someone to finish your homework for you are you?
          • 2. Re: String Tokenizer
            807606
            I do not want anyone to finish my homework for me, I have tried several diffent times to use StringTokenizer and I have not had any luck. I included the code I have so far because I know it runs with no errors. I cannot figure out to make the StringTokenizer work.
            • 3. Re: String Tokenizer
              796447
              I do not want anyone to finish my homework for me, I
              have tried several diffent times to use
              StringTokenizer and I have not had any luck. I
              included the code I have so far because I know it
              runs with no errors. I cannot figure out to make the
              StringTokenizer work.
              I bet most of your trouble is due to the fact that you're reading a .java source code file, not a file containing an appropriate set of data from which to read.
              • 4. Re: String Tokenizer
                807606
                Ok, that was one of my questions.

                I was looking at some of my sample code and it was reading from a .java file and some were .txt files. I wasnt sure which to use.


                Thanks