Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.util.Scanner;
- import java.io.*;
- /**
- *
- * @author Pel
- */
- public class FileProg3 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- throws FileNotFoundException, IOException{
- Scanner input4= new Scanner(new File("averages.txt"));
- String pathname="averages.txt";
- File file=new File(pathname);
- Scanner input =null;
- try
- {
- input4=new Scanner(file);
- }
- catch(FileNotFoundException ex)
- {
- System.out.println("***cannot open "+pathname+"***");
- System.exit(1);
- }
- int numGrade=input4.nextInt();
- int numKid=0;
- int sum=0;
- int totalSum=0;
- while(input4.hasNext())
- {
- System.out.print(input4.next());
- numKid++;
- for(int x=0;x<numGrade;x++)
- {
- sum=input4.nextInt()+sum;
- }
- totalSum=totalSum +sum;
- int average=sum/numGrade;
- System.out.print(" "+average);
- sum=0;
- System.out.println();
- }
- int totalAverage=totalSum/(numKid*numGrade);
- System.out.println(numKid+" kids took the test");
- System.out.println("Average= "+totalAverage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement