if -else is used for both true and false for a condition.
here, if the condition is true .next statement1 will be executed and skips statement2
if the condition is false next statement2 will be executed and skips satement1. using else part is not mandatory, let’s see one example
System. out.println("Enter your age");
System.out.println("you are allowed to enter this website");
System.out.println("you are not allowed to enter this website");
Enter your age
you are not allowed to enter this website
here, in this example, the condition is, the age of the person should be either 18 or more to enter the website. that means if the test expression given (a>=18) is true,it displays the first message”you are allowed to enter this website”,it it is false, then the second message is displayed “you are not allowed to enter this website”.