Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import type.lib.*;
  4.  
  5. public class Check10A
  6. {
  7. public static void main(String[] args)
  8. {
  9. PrintStream output = System.out;
  10. Scanner input = new Scanner(System.in);
  11.  
  12. final int SENTINEL = 0;
  13. int sum = 0;
  14. output.print("Enter your integers\n(Negative=sentinel)\n");
  15.  
  16. List<Integer> list = new ArrayList<Integer>();
  17.  
  18. for (int num = input.nextInt(); num >= SENTINEL; num = input.nextInt())
  19. {
  20. list.add(num);
  21. sum = sum + num;
  22.  
  23. }
  24. if(list.isEmpty() == true)
  25. {
  26. output.println("Your list is empty!");
  27. }
  28. else
  29. {
  30. double average = (double)sum / list.size();
  31. output.printf("The average is: %f\n", average);
  32. Iterator<Integer> it = list.iterator();
  33. Collections.sort(list);
  34. output.println("The sorted, distinct, above-average elements:");
  35. for(;it.hasNext();)
  36. {
  37. double element = (double)it.next();
  38. if(element > average)
  39. {
  40. output.printf("%d ", (int)element);
  41. }
  42. }
  43. output.println();
  44. }
  45.  
  46.  
  47.  
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement