Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import java.util.Scanner;
  7. import java.io.*;
  8.  
  9.  
  10. /**
  11. *
  12. * @author Pel
  13. */
  14. public class FileProg3 {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args)
  20. throws FileNotFoundException, IOException{
  21. Scanner input4= new Scanner(new File("averages.txt"));
  22. String pathname="averages.txt";
  23. File file=new File(pathname);
  24. Scanner input =null;
  25.  
  26. try
  27. {
  28. input4=new Scanner(file);
  29. }
  30. catch(FileNotFoundException ex)
  31. {
  32. System.out.println("***cannot open "+pathname+"***");
  33. System.exit(1);
  34. }
  35.  
  36.  
  37. int numGrade=input4.nextInt();
  38. int numKid=0;
  39. int sum=0;
  40. int totalSum=0;
  41. while(input4.hasNext())
  42. {
  43. System.out.print(input4.next());
  44. numKid++;
  45.  
  46. for(int x=0;x<numGrade;x++)
  47. {
  48. sum=input4.nextInt()+sum;
  49.  
  50.  
  51. }
  52. totalSum=totalSum +sum;
  53. int average=sum/numGrade;
  54.  
  55.  
  56. System.out.print(" "+average);
  57. sum=0;
  58. System.out.println();
  59.  
  60. }
  61. int totalAverage=totalSum/(numKid*numGrade);
  62. System.out.println(numKid+" kids took the test");
  63. System.out.println("Average= "+totalAverage);
  64.  
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement