Control Statements ================== program: more than one statements sum of two numbers: n1 = 10 n2 = 20 s = n1 + n2 println(s) System.out.println("Hello"); => compiled ==> byte code (class code) ==> JVM ==> object ==> execute ==> Op ==> Any java program can have "sequential execution" by default. WAP in Java to print "hello" for 5-times ==> Control statements are required for: 1) when we want to execute the same block of code for several number of times repeatedly 2) to make java program execution based on the selection 3) when we want to make jump from one block of code to another block of code. if num % 2==0: goto part_01 else: goto part_02 part_01: "Even number" part_02: "Odd number" ========= control statements are: three types: 1) Conditional Statements/Selection Statements 2) Loop Statements/Iterative Statements 3) Transfer Statements/Jumping Statements 1) Conditional Statements/Selection Statements =============================================== Based on the condition, the specific block of code can execute ==> total 4 conditionals: 1) if statement 2) if else statement 3) nested if else statement 4) if else if else ladder 1) if statement =============== Syntax: if(condition) { statement-1; statement-2; } // WAP in Java to check the number is negative. If it is negative convert into positive. import java.util.Scanner; class simpleIf{ public static void main(String args[]) { Scanner obj = new Scanner(System.in); System.out.println("Enter a number:"); int n = obj.nextInt(); if(n < 0) { n = -n; // unary minus operator System.out.println("After the conversion, the number is = "+n); } System.out.println("Original Number = "+n); System.out.println("Bye Bye"); } } =============================== // WAP in java to check whether the number ids negative or positive. If it is negative convert into positive. If it is posituve convert into negative. import java.util.Scanner; class SimpleIf{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a value:"); int n = sc.nextInt(); // checking the number is positive or not if(n > 0) { n = -n; System.out.println("After the conversion, the number is = "+n); } // checking the number is negetive or not if(n < 0) { n = -n; System.out.println("After the conversion, the number is = "+n); } } } ================================================== if else statement: ================== Syntax: if(condition) { statements; // if block statements } else { statements; // else block statements } // WAP in java to check whether the number is negative or positive. If it is negative convert into positive. If it is posituve convert into negative. import java.util.Scanner; class SimpleIf{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a value:"); int n = sc.nextInt(); // checking the number is positive or not if(n > 0) { n = -n; System.out.println("After the conversion, the number is = "+n); } // checking the number is negetive or not else { n = -n; System.out.println("After the conversion, the number is = "+n); } } } ============================================== Assignment: =========== 1) WAP IN JAVA TO CHECK WHETHER THE NUMBER IS EVEN OR ODD. 2) WAP IN JAVA TO FIND THE BIGGEST NUMBER AMONG TWO INTEGERS. 3) WAP IN JAVA TO FIND THE SUM OF TWO NUMBERS IF FIRST NUMBER IS LESS THAN THE SECOND OTHERWISE PRINT THEIR DIFFERENCE. HINT: f < s: f + s otherwise: f - s