Page 90 - iPro_trackGPT_V5_Class8
P. 90
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:
Logical Errors
A logical error is a mistake in a program that makes it run and compile without problems but
gives wrong or unexpected results. These errors are hard to find because the compiler can't
detect them. To find logical errors, you have to carefully check your code. Logical errors are
also known as semantic errors. For example, if a programmer accidentally adds two numbers
instead of dividing them, the result will be incorrect.
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.
WRITING SOME MORE PROGRAMS
So far, we have learned about conditional statements, looping statements, and jump statements
in Java. We have also written programs using these concepts. Let us now create some other
programs.
88 TrackGPT iPRO (V5.0)-VIII

