Skip to main content

Section 5.2 WriteSelection-WE1-P1

Subgoals for Writing Selection Statements.

If Statement
  1. Define how many mutually exclusive paths are needed
  2. Order from most restrictive/selective group to least restrictive
  3. Write if statement with Boolean expression
  4. Follow with true bracket including action
  5. Follow with else bracket
  6. Repeat until all groups and actions are accounted for
OR Switch Statement
  1. Determine variable / expression for mutually exclusive ranges
  2. Write switch statement based on variable / expression
  3. Each range is a ‘case’
  4. Include break statements and default case if needed

Subsection 5.2.1 Write Relational Expressions

To correctly write selection statements, you must write the conditional expressions correctly. To do this, you generally need to translate the requirements, written in English, to a correct boolean expression. Below are practice questions for this skill.

Subsection 5.2.2

Exercises Exercises

1.
    Q1: Which of the following is the correct Java expression that is equivalent to the English expression “weight is greater than 100”?
  • weight > 100
  • weight<100
  • weight >= 100
  • weight >> 100
2.
    Q2: Which of the following is the correct Java expression that is equivalent to the English expression “a not equal to 0”?
  • a NOT EQUAL 0
  • a NOT= 0
  • a != 0
  • a !== 0
3.
    Q3: Which of the following is the correct Java expression that is equivalent to the English expression “apple and orange are not the same”?
  • "apple" != "orange"
  • apple != orange
  • NOT ("apple.equals("orange"))
  • apple !== orange
4.
    Q4: Which of the following is the correct Java expression that is equivalent to the English expression “not done”?
  • NOT done
  • != done
  • !done
  • done = false
You have attempted of activities on this page.