Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Suarez;
- import java.io.File;
- import java.io.IOException;
- import java.util.Scanner;
- public class AveragePrice {
- public static void main(String[] args) throws IOException {
- File fileInput = new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\Prices");
- Scanner input = new Scanner(fileInput);
- while(input.hasNextLine()){
- String line = input.nextLine();
- Scanner lineBreaker = new Scanner(line);
- String product = lineBreaker.next();
- double total = 0;
- int count = 0;
- while (lineBreaker.hasNextDouble()){
- total = total = total + lineBreaker.nextDouble();
- count++;
- }
- System.out.println("The average price of "+product+" is " + total/count);
- }
- }
- }
- PRICES:
- coffee 10.00 20.00 30.00
- coke 11.00 12.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement