Skip to main content

Practice Code Structure

Section 1.25 Code Comprehension

Activity 1.25.1.

    Look at the first code block. Which of the following options have the same functionality as it (i.e., they produce the same output for the same inputs)? You can check the Hint for some input examples.
    public static boolean canPlayoutside(String weather) {
       if (weather.equals("rainy")) {
            return false;
       } else {
            return true;
       } 
    }
    
    Hint.
    You can use the following test cases to compare the code blocks’ functionality.
    • canPlayoutside("rainy")
    • canPlayoutside("sunny")
    • canPlayoutside("cloudy")
    Select all that apply.
  • public static boolean canPlayoutside(String weather) {
       if (weather.equals("rainy")) {
            return false;
       } return true;
    }
    
  • Correct!
  • public static boolean canPlayoutside(String weather) {
       if (!weather.equals("rainy")) {
            return true;
       } return false;
    }
    
  • Correct!
  • public static boolean canPlayoutside(String weather) {
       return !weather.equals("rainy");
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.