SJSU/Udacity CS046

Lesson 5.2 - Decisions

  1. Quiz: Comparing Decimals
  2. Quiz: Comparing Strings
  3. Quiz: What Does Null Mean?
  4. Quiz: Find the Error
  5. Quiz: And, Or, Not
  6. Quiz: Or
  7. Quiz: Both Threes
  8. Quiz: Exactly One Three
  9. Boolean
  10. Quiz: Using Booleans
  11. Quiz: Nested If
  12. Quiz: Elevator Demo with Input Validation
  13. Advice to Students

Quiz: Find the Error

Match the errors with these explanations:

a) Strings are objects and should be compared using equals

b) The string friends will never be null

c) Loss of precision may prevent this statement from ever being true even when a person would see that it should be true

d) This statement tries to change the value of the variable instead of comparing it

if (friends = "")
{
   return "no friends left";
}
d
if (friends == null)
{
   return "no friends left";
}
b
if (friends == "")
{
   return "no friends left";
}
a
if (numFriends == numPeople * 0.33)
{
   return "friends with 1 in 3 people";
}
c

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =