Logical errors are caused by the fact that the software specification is not respected. The program is compiled and executed without errors, but does not generate the requested result.
Let us see some examples of logical errors:
Example 1: Errors in the performed computation:
public static int sum(int a, int b) { return a - b ; } // this method returns the wrong value wrt the specification that requires // to sum two integers
Example 2: Non termination:
String s = br.readLine(); while (s != null) { System.out.println(s); } // this loop does not terminate