fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class AvgNums {
  6. public static void main(String args[])throws IOException {
  7.  
  8. int count=0;
  9.  
  10. double sum= 0.0;
  11.  
  12.  
  13. FileWriter fout = new FileWriter("test.txt");
  14. fout.write("2 3.4 5 6 7.4 9.1 10.5 готово");
  15. fout.close();
  16. FileReader fin = new FileReader("test.txt");
  17. Scanner src = new Scanner(fin);
  18.  
  19.  
  20. while(src.hasNext()) {
  21. if(src.hasNextDouble()) {
  22. sum += src.nextDouble();
  23. System.out.println(sum);
  24. count++;
  25. }
  26. }
  27. if(src.hasNext()) {
  28. String str = src.next();
  29.  
  30. if(str.equals("готово"))
  31. {
  32. return;
  33. }
  34. else {
  35. System.out.println("Ошибка формата файла.");
  36. return;
  37. }
  38. }
  39.  
  40. src.close();
  41. System.out.println("средне равно: " +sum/count);
  42. }
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class AvgNums is public, should be declared in a file named AvgNums.java
public class AvgNums {
       ^
1 error
stdout
Standard output is empty