Page 89 - TP_iPlus_V2.1_Class8
P. 89
For example:
public class RuntimeError{
public static void main(String args[])
{
int a = 100;
int b = 0;
int c = a / b;
System.out.println(c);
}
}
If we compile the preceding program, it compiles successfully. But, when we run the program,
it will show an error message as follows:
Runtime Error
Logical Errors
A logical error is a type of error due to which a program compiles and executes successfully
but gives an unexpected or incorrect result. It is very difficult to find this type of error in the
program. The compiler will not be able to find logical errors. We need to read our programs
deeply to find logical errors. Logical errors are also called 'Semantic Errors.' For example, if
a programmer accidentally adds two numbers instead of dividing them, then he or she will
not get the expected output.
public class LogicalError{
public static void main(String args[])
{
int a = 100;
int b = 200;
int c = a + b;
System.out.println("The result of division is: "+c);
}
}
When we compile and execute the preceding program, it does not show any error messages. But,
it shows incorrect output because we have used the plus (+) sign instead of the divide (/) sign.
87
Conditional, Looping and Jump Statements in Java

