Skip to main content

Practice Code Structure

Section 1.26 Identification

Activity 1.26.1.

    These code blocks are the ones you saw in the previous question and they all have the same functionality. Among these options which one is preferable?
  • public static boolean canPlayoutside(String weather) {
       if (weather.equals("rainy")) {
            return false;
       } else {
            return true;
       } 
    }
    
  • This code can be improved!
  • public static boolean canPlayoutside(String weather) {
       if (weather.equals("rainy")) {
            return false;
       } return true;
    }
    
  • This code can be improved!
  • public static boolean canPlayoutside(String weather) {
       if (!weather.equals("rainy")) {
            return true;
       } return false;
    }
    
  • This code can be improved!
  • public static boolean canPlayoutside(String weather) {
       return !weather.equals("rainy");
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.