The "main function" in Java main(String[]) has to be:
- public
- static
- void
- called main
- and accepting and only an array of strings as its arguments.
If you deviate from that in any way, it won't work. An example is: public static void main(String[] line)
That means you have to change a few things in your program.
Scanner only accepts strings, not arrays of strings. So build a string from that array, as so:
StringBuilder joinedLine = new StringBuilder();
for (String word : line) {
joinedLine.append(word).append(" ");
}
Scanner lineScan = new Scanner(joinedLine);
Of course it is possible that you could just do this instead:
try {
for (String word : line) {
Scanner wordScan = new Scanner(word);
while (lineScan.hasNextInt()) {
int next = lineScan.nextInt();
sum += next;
count++;
// ......
}
}
} catch (NumberFormatException e) {}
The next thing you have to change is that you can't return a value from main(String[]). You could throw an Error, a Runtime Exception, a declared Exception or even call System.exit(int) which accepts an integer status. A nonzero status means there was an abnormal termination. (So System.exit(0); is effectively the same as return;.)