import java.util.* ; public class if1 { public static void main( String args[] ) { int x1 = 5 ; int y1 = 5 ; System.out.println( "Enter a value between 1 and 10" ) ; Scanner scanner = new Scanner(System.in); x1 = scanner.nextInt(); if ( x1 <= 5 ) System.out.println( "Value was less than or equal to 5." ) ; //Common error the ; is the empty statement associated //if . The statement following it, is //executed every time. if ( x1 > 5 ); System.out.println( "Value was greater than 5." ) ; //Correct way if ( x1 > 5 ) System.out.println( "Value was greater than 5." ) ; if ( x1 <= 5 ) { //Block associate multiple statement with if System.out.println( "Inside block 1st line:Value was less than or equal to 5." ) ; System.out.println( "Inside block 2nd line: Value was less than or equal to 5." ) ; } if ( x1 <= 5 ) System.out.println( "Inside if else: Value was less than or equal to 5." ) ; else System.out.println( "Inside if else: Value was greater than 5." ) ; //Nested if We can have an if statement inside another if if ( x1 <= 5 ) { System.out.println( "Inside nested if: Value was less than or equal to 5." ) ; if ( x1 <= 3 ) System.out.println( "Inside nested if: Value was less than or equal to 3." ) ; else System.out.println( "Inside nested if: Value was between 3 and 5." ) ; } else System.out.println( "Inside if else: Value was greater than 5." ) ; //Multi way if else if if ( x1 <= 3 ) System.out.println( "Inside multi-way if: Value was less than or equal to 3." ) ; else if ( x1 <= 5 ) System.out.println( "Inside multi-way if: Value was between 4 and 5." ) ; else if ( x1 <= 7 ) System.out.println( "Inside multi-way if: Value was between 6 and 7." ) ; else System.out.println( "Inside multi-way if: Value was between 8 and 10." ) ; } } //class