Question: Complete the following java program which scans a file containing only numbers and white space, and prints out the average value of all the numbers

Complete the following java program which scans a file containing only numbers and white space, and prints out the average value of all the numbers in the file. For instance, given a file called test containing the numbers: 2.4 3.4 5.8 6.0 7 -3 12.2 8, and given that your program is called by doing % java Problem7 test at the command line, your program will produce the following output.

Output: The average value in file test is 5.225

Your program will check that the number of command line arguments is equal to 1, and will initialize a Scanner object (in an appropriate try-catch block) pointing to the file named on the command line. If any of these tests fail, your program will exit with an error message. You may assume that the file will contain at least one number.

Outline :

// Problem7.java

import java.util.Scanner;

import java.io.*;

class Problem7{

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

// your begins here

// your code ends here

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!