Results 1 to 3 of 3
  1. #1
    zhider is offline Member
    Join Date
    Oct 2012
    Posts
    37
    Rep Power
    0

    Default Read from file program.

    I need to make a program that reads from a file, to add up 20 scores, from said file and find the mean. Right now I have it reading the values and printing them out, but not adding them up. How would I make it add up all values of "value"
    Java Code:
     public static void main(String[] args) throws IOException, FileNotFoundException {
            processFile("c:\\scores.txt");
         }
    public static void processFile (String filename) throws IOException, FileNotFoundException {
         String line;double value;
         BufferedReader inputReader = new BufferedReader (new InputStreamReader(new FileInputStream(filename)));
              while (( line = inputReader.readLine()) != null){
              value= Double.parseDouble(line);
              System.out.println(value);
              value=value+value;
              }
         inputReader.close();
              }
    }

  2. #2
    zhider is offline Member
    Join Date
    Oct 2012
    Posts
    37
    Rep Power
    0

    Default Re: Read from file program.

    I actually dont have it printing value in the code I posted.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Read from file program.

    So, rather than replacing the contents of the value variable every time, why not just add to it? Initialize it to 0, then use += on each loop instead of =

Similar Threads

  1. Replies: 8
    Last Post: 07-25-2012, 11:00 AM
  2. Replies: 4
    Last Post: 11-03-2010, 07:17 PM
  3. how to read excel file through java program
    By madhuragowda in forum New To Java
    Replies: 2
    Last Post: 04-16-2010, 09:53 AM
  4. Replies: 2
    Last Post: 04-03-2009, 05:37 AM
  5. Replies: 0
    Last Post: 02-11-2009, 10:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •