Reputation: 1
Here is what i've got so far. I dont't know how to print the lowest and highest number to the screen. Any help would be appreciated.Thanks.
BufferedReader openFile;
try{
openFile = new BufferedReader(new FileReader("LABEX10.txt"));
}
catch(FileNotFoundException e){
System.out.println("Could not open file LABEX10.txt");
System.exit(0);
}catch(IOException ex){
System.err.println(ex);
}
}
}
Upvotes: 0
Views: 56
Reputation: 61168
Using Java 8:
final Path path = Paths.get("LABEX10.txt");
try (Stream<String> lines = Files.lines(path)) {
final LongSummaryStatistics summary = lines
.mapToLong(Long::parseLong)
.summaryStatistics();
System.out.printf("range [%d .. %d]%n", summary.getMin(), summary.getMax());
}
This approach is more modern than the proposed duplicate.
Upvotes: 2