Name the type of error (syntax, runtime or logical error) in each case given below:
(i) Math.sqrt (36-45)
(ii) int a;b;c;
Solution
TC++ #4216
(i) Math.sqrt (36-45)
This will return NaN (Not a Number) to indicate that proper result is not possible. One may consider it a runtime error as it comes at runtime. But technically speaking it is a Logical Error as no exception occurs but result is undesirable. It is just a case where the result is not possible to due to limitation of the method used.
(ii) int a;b;c;
This would be a Syntax Error found at compile time erroras the variables b and c do not have their data types declared.
Notes
Math.sqrt(-9) and square root of a negative number are not real values. There are alternative ways to handle complex and imaginary numbers in java but sqrt() method will return NaN.