fork download
  1. import java.util.*;
  2.  
  3. class Main
  4. {
  5. public static void main (String[] args) throws java.lang.Exception
  6. {
  7. Scanner in = new Scanner(System.in);
  8. Vector a,b;
  9. a = new Vector();
  10. b = new Vector();
  11. double cur, sum = 0;
  12.  
  13. while(in.hasNext()){
  14. cur = in.nextDouble();
  15. a.add(cur);
  16. sum += cur;
  17. }
  18. //Если последовательность состоит только из одного числа.
  19. if(a.size() < 2){
  20. System.out.print("The sequence must consist of at least two elements.");
  21. }
  22. else{
  23. //Заполняем вектор b.
  24. for(int i=0; i < a.size(); ++i){
  25. b.add((sum - (double)(a.elementAt(i)))/(a.size() - 1));
  26. }
  27.  
  28. //Выводим ответ.
  29. System.out.print("The arithmetic average of all elements of this series except the element №i is:\n");
  30. for(int i=0; i < b.size(); ++i){
  31. System.out.print("for i = " + (i+1) + ": " + b.elementAt(i) + '\n');
  32. }
  33. }
  34. }
  35. }
Success #stdin #stdout 0.07s 4575232KB
stdin
4
stdout
The sequence must consist of at least two elements.