Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //practical 1 question 1
  2. package prac1;
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.List;
  6.  
  7.  
  8. /**
  9. *
  10. * @author Student
  11. */
  12. public class Prac1 {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. List<Integer> scores = new ArrayList();
  19. int min, max, average, sum=0;
  20. scores.add(100);
  21. scores.add(50);
  22. scores.add(80);
  23. scores.add(40);
  24. scores.add(99);
  25.  
  26. min = Collections.min(scores);
  27. max = Collections.max(scores);
  28.  
  29. //display all test scores
  30. for(int score:scores){
  31. System.out.println(score + ", ");
  32. }
  33.  
  34. //display the lowest score
  35. System.out.println("\nMin: " + min);
  36.  
  37. //display the highest score
  38. System.out.println("\nMax: " + max);
  39.  
  40. //display the average score
  41. for(int score:scores){
  42. sum += score;
  43. }
  44. average = sum/scores.size();
  45. System.out.println("\nAverage: " + average);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement