Posts

Showing posts with the label switch-case

Control Statements in java

Image
Control Statements in java There are three control statements in java: Selection  statements Iteration statements or looping statements Jump statements Break statement 1.Selection statements: if-else statements switch case statements Which path to choose:your choice 1.if-else statements: With if only: Syntax:if(condition) { statement1; statement2; statement3; statement4; .......... } With if-else statements: Syntax: if(condition) { statement1; statement2; statement3; statement4; .......... } else { statement1; statement2; .......... }  Here condition is a conditional statement containing the condition operators only such as <,>,>=,<=,==,!=. Example:if(age>=18) {//if the age is greater than 18 then print this System.out.println("You are allowed to vote"); } else { System.out.println("Grow up!!wait for some years.."); } Take care of the curly brackets that ...