← Java from Scratch Lesson 49 of 88 · 10 XP

Errors

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

There are three kinds of errors:

  1. Compile errors — javac can't understand the program: a missing ;, a typo in a name, the wrong type. The program won't even start. The compiler writes the file, the line and what's wrong: Main.java:5: error: ';' expected int x = 5 ^
  2. Runtime errors (exceptions) — the program started but crashed: division by zero, going out of an array's bounds, null instead of an object.
  3. Logic errors — the program runs and reports no error, but the result is wrong. Neither the compiler nor the JVM will find them — only tests and debugging.

How to read compile errors: start with the first one — the rest are often its consequences. Common messages: cannot find symbol (a typo, or you forgot to declare something), incompatible types (the wrong type), missing return statement, ';' expected.

Task. The program has four compile errors. Find and fix them — the program should print the sum and the average of the numbers from the input.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.