Advertisement
AntonKorzhan7

Loop5 Java

Oct 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Loops5
  4. {
  5. static double [] scores;
  6.  
  7. static Scanner input = new Scanner(System.in);
  8.  
  9. public static void main(String[] args)
  10. {
  11. System.out.println("How many scores to enter?");
  12. int sizeOFArray = input.nextInt();
  13.  
  14. scores = new double[sizeOFArray];
  15. input();
  16. calcAverage();
  17. }
  18.  
  19. public static void input()
  20. {
  21. for(int i=0; i < scores.length; i++)
  22. {
  23.  
  24. System.out.println("Enter score");
  25. scores[i] = input.nextDouble();
  26.  
  27. }
  28. System.out.println("All marks entered.");
  29. output();
  30. }
  31.  
  32. public static void output()
  33. {
  34. for(int i=0; i < scores.length; i++)
  35. {
  36. System.out.println(scores[i]);
  37.  
  38. }
  39.  
  40. }
  41.  
  42. public static void calcAverage()
  43. {
  44. double total =0;
  45.  
  46. for(int i =0; i< scores.length; i++)
  47. {
  48. total = total + scores[i];
  49. }
  50. double average = total/scores.length;
  51. System.out.println("The average is " + average);
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement