If and Else
Today we are going to discuss about if else and else if statement with some examples and have a better understanding of it. if :- This is a conditional statement which is use when you want some operation only be excute if your given condition is true. Let us see its syntax and try to understand it. if (condition) { // Set of instructions } Now see if condition given turns out to be true only then we will enter the if block and execute the set of instructions. Question 1: Write a program in Java to print even numbers present between 1 to 20 using if statement. class Even { public static void main( String args [ ] ) { int i ; for(i = 1 ; i< 20; i++) if ( i%2 == 0 ) { System.out.println(i); } } } Dry Run First i value will 1 then it will enter for loop and compiler will check the condition and as it is false it will not execute the if block. Now i value will be 2 which is a even no and s