Respuesta :

Answer:

SELECTION STRUCTURES

Selection statements allow you to control the flow of program execution on the basis of the outcome of an expression.

different selection structures are:

1)if statements

2)if-else statements

3)if-else-if statements

4)switch statements

Explanation:

THE IF STATEMENTS

the first statement in the if block is only executed when the specified condition is true.If the condition is false then the contained statement will be skipped and execution continued with the rest of the program.

example:

public class IfDemo

{

public static void main(String[] args) {

int age;

Scanner inputDevice = new Scanner(System.in);

System.out.print("Please enter Age: ");

age = inputDevice.nextInt();

if(age > 18)

System.out.println("above 18 ");

}

}

THE IF-ELSE STATEMENTS

if the specified condition in the if statement is false, then the statement after else will be executed.

example:

public class IfElseDemo

{

public static void main( String[] args )

{

int age;

Scanner inputDevice = new Scanner( System.in );

System.out.print( "Please enter Age: " );

age = inputDevice.nextInt();

if ( age >= 18 )

System.out.println( "above 18 " );

else

System.out.println( "below 18" );

}

}

THE IF-ELSE-IF STATEMENTS

the statements after else can be another if or if-else statement, multiple if-else statements.When the condition is true, the associated statement will be executed and remaining conditions will be bypassed.

example:

public class IfElseIfDemo

{

public static void main( String[] args )

{

int age;

Scanner inputDevice = new Scanner( System.in );

System.out.print( "Please enter Age: " );

age = inputDevice.nextInt();

if ( age >= 18 && age <=35 )

System.out.println( "between 18-35 " );

else if(age >35 && age <=60)

System.out.println("between 36-60");

else

System.out.println( "not matched" );

}

}

THE SWITCH STATEMENTS

It is a multi way branch statement. It defines multiple paths of execution of a program.It provides a better alternative than if-else-if statements.

example:

public class SwitchDemo

{

public static void main( String[] args )

{

int age;

Scanner inputDevice = new Scanner( System.in );

System.out.print( "Please enter Age: " );

age = inputDevice.nextInt();

switch ( age )

{

case 18:

System.out.println( "age 18" );

break;

case 19:

System.out.println( "age 19" );

break;

default:

System.out.println( "not matched" );

break;

}

}

}