1223 Process scores in a text file on the Web Suppose that t

**12.23 (Process scores in a text file on the Web) Suppose that the text file on the

Web http://cs.armstrong.edu/liang/data/Scores.txt contains an unspecified number

of scores. Write a program that reads the scores from the file and displays their

total and average. Scores are separated by blanks.

*JAVA*

Solution

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class Demo {
   public static void main(String[] args) throws Exception {

       URL line = new URL(\"http://cs.armstrong.edu/liang/data/Scores.txt\");
       BufferedReader in = new BufferedReader(new InputStreamReader(
               line.openStream()));
       String inputLine;
       int total = 0;
       int count = 0;
       int num = 0;
       while ((inputLine = in.readLine()) != null) { // Note change
           System.out.println(\"Read the string\");
           // split into words
           String words[] = inputLine.split(\" \");
           // For each word in the line
           for (String str : words) {
               System.out.println(str);
               num = Integer.parseInt(str);
               total = total + num;
               count++;

           }
           System.out.println();

       }
       System.out.println(\"Total is: \" + total);
       System.out.println(\"Average is:\" + (total / count));
       in.close();
   }
}

**12.23 (Process scores in a text file on the Web) Suppose that the text file on the Web http://cs.armstrong.edu/liang/data/Scores.txt contains an unspecified n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site