Page 86 - iPlus_Ver_2.0_class_8
P. 86
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 devision 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.
i + WRITING SOME MORE PROGRAMS
Till now, we have learned conditional, looping and jumping statements of Java. We have also
created related programs in Java. Let us now create some other programs.
Program 1: Write a Java program to print all the even numbers between 1 and N by using the
while loop. The value of N should be taken from the user as input.
84
iPlus (Ver. 2.0)-VIII

