113k views
3 votes
Write a program to read data from a file named problem 2. ext. This file has three exams data (floating point data) in three columns for the students in a class. Find the average and the highest score in the class for the Second exam which is located in the Second column of the file. Assume that the file has neither initial number of total lines of data values nor any sentinel signals. That is your program need to show that you have no idea how many data lines are there) 77 90 86 66.5 88 80.5 95 75 80 80 79 89 70.5 81 Note: If you don't have the software access then you don't have to worry about saving the data file. Just write your code assuming the text file is saved in the right location.

User Milczi
by
5.0k points

1 Answer

1 vote

Answer:

import java.io.File; // Import the File class

import java.io.FileNotFoundException; // Import this class to handle errors

import java.util.Scanner; // Import the Scanner class to read text files

public class ReadFile {

public static void main(String[] args) {

try {

File myObj = new File("filename.txt");

Scanner myReader = new Scanner(myObj);

while (myReader.hasNextLine()) {

String data = myReader.nextLine();

System.out.println(data);

}

myReader.close();

} catch (FileNotFoundException e) {

System.out.println("An error occurred.");

e.printStackTrace();

}

}

}

Step-by-step explanation:

this will read the file and print it out, to do the rest have it take the data and use some "java math" and then print the answers to either console or a file of your choice.

User Robert Pal
by
4.6k points