// CSE 142 Lecture 14 // Files // Scans a file of gas price data and prints the average price // of gas in Belgium and the United States. import java.io.*; // For File, FileNotFoundException import java.util.*; // For Scanner public class GasPrices { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("gasprices.txt")); double belgiumAvg = 0; double usaAvg = 0; int count = 0; while (input.hasNext()) { belgiumAvg += input.nextDouble(); usaAvg += input.nextDouble(); count++; input.next(); } System.out.printf("Belgium average: $%.2f/gal\n", belgiumAvg / count); System.out.printf("USA average: $%.2f/gal\n", usaAvg / count); } }