public static void main(String args[]) throws NumberFormatException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
int counter = 0;
while(true) {
int input = Integer.parseInt(reader.readLine());
if(input == -1) break;
sum += input;
counter++;
}
System.out.println(sum/counter);
}
The current program is giving me the correct output but I cannot submit it.Not compiling
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Andrew
3 April 2019, 17:37
If it's not compiling, IntelliJ should be giving you some kind of error message. What are you seeing?
You will not get the correct output. Hint: look at the requirements section. Run your code with those inputs and compare your output to the required output?
0
Clayton
3 April 2019, 17:48
http://prntscr.com/n71s78
I'm using Eclipse and it's not giving me an error message. The IDE on codegym is saying: http://prntscr.com/n71sfu
0
Andrew
3 April 2019, 17:53
Screenshots very helpful, thanks! It looks like the error is on line 9 on your submitted code, an issue with the IOException. Have you imported it?
+2
Andrew
3 April 2019, 17:57
If the exception is part of the java.lang library, it is imported automatically behind the scenes. That's why you don't always have to import classes (like with NumberFormatException). But when you want to use a class outside of the java.lang library, like java.io or java.util, you have to import it or the compiler won't be able to find the reference.
+1
Clayton
3 April 2019, 20:38
Thanks
0