Name and describe three types of branching mechanisms and give an example of each.

What will be an ideal response?


Three types of branching mechanisms include the if-else statement, the multi-way if-else
statement, and the switch statement. An if-else statement chooses between two alternative
statements based on the value of a Boolean expression. If you only need to perform an action if a
certain condition is true, then the else part of an if-else statement can be omitted. A multi-way if-
else statement allows several conditions to be evaluated. The first condition that evaluates to true, is
the branch that is executed. The switch statement is another multi-selection branching mechanism.
A switch evaluates a controlling expression and executes the statements in the matching case label.
```
If – else example: if ( taxableIncome > 30000)
taxRate = .135;
else
taxRate = .075;

Multi-way if-else example:

If(taxableIncome < 10000)
taxRate = .0425;
else if(taxableIncome < 30000)
taxRate = .075;
else
taxRate = .135;

Switch example: char myChar = ‘b’;
switch(myChar)
{
case ‘a’:
System.out.println(“It is an A”);
break;

case ‘b’:

System.out.println(“It is a B”);

break;
case default:

System.out.println(“Default case”);
break;

}
```

Computer Science & Information Technology

You might also like to view...

____________ is a free programming environment that is available for download from the Microsoft Web site.

a. Visual Studio 2015 Community Edition b. Visual Studio 2015 Professional c. The MSDN library d. Internet Explorer

Computer Science & Information Technology

__________ is a data analysis technique used by decision makers to quickly get answers to complex queries that encompass multiple factors, such as locations, revenue, time periods, and employee status.

A. SQL B. OLAP C. NoSQL D. TPS

Computer Science & Information Technology

An example of a use of cout is ____.

A. cout >> "Hello World"; B. cout -> "Hello World"; C. cout << "Hello World"; D. cout < "Hello World";

Computer Science & Information Technology

A technician wants to remotely log into an office computer using remote desktop. The technician needs to do this in a secure manner. Which of the following would accomplish this?

A. VPN B. Telnet C. VLAN D. Tagged packets

Computer Science & Information Technology