The following statement is intended to print the circumference of a circle with radius 4, using 3.14 for pi. What kind of error does this code most clearly demonstrate?
System.out.println(3.14 * 4);
25.12.Explanation
A logic error occurs when the program runs without crashing but produces the wrong result. This statement follows Java's grammar and completes, so the problem is in what it calculates, not in whether it can run.
- A is not correct: a syntax error prevents compilation, and nothing here breaks Java's grammar.
- C is not correct: a run-time error interrupts a program during execution; this statement is not interrupted.
- D is not correct: the statement does not print
25.12, so there is an error.