Three examples of logical error and Three examples of syntax error
Answers
Answer:
A logic error (or logical error) is a mistake in a program's source code that results in incorrect or unexpected behavior. ... For example, assigning a value to the wrong variable may cause a series of unexpected program errors. Multiplying two numbers instead of adding them together may also produce unwanted results.
Explanation:
Syntax errors are mistakes in using the language. Examples of syntax errors are missing a comma or a quotation mark, or misspelling a word. MATLAB itself will flag syntax errors and give an error message.
Answer:
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.
Syntax errors are mistakes in using the language. Examples of syntax errors are missing a comma or a quotation mark, or misspelling a word. MATLAB itself will flag syntax errors and give an error message.