Skip to main content

Practice Code Structure

Section 1.4 Identification

Activity 1.4.1.

    These code blocks are the same as the ones you saw in the previous question, and they all have the same functionality. Among these options, which one is preferable?
  • public static String whereToPlay(boolean isSunny, int temperature) {
        if (isSunny) {
            if (temperature > 70) { 
                return "play outside";    
            }
        } 
        return "play inside";
    }
    
  • This code can be improved!
  • public static String whereToPlay(boolean isSunny, int temperature) {
       if (!isSunny) {
          return "play inside";
       }
       if (temperature <= 70) { 
          return "play inside";    
       } 
       return "play outside";
    }
    
  • This code can be improved!
  • public static String whereToPlay(boolean isSunny, int temperature) {
       if (isSunny && temperature > 70) { 
          return "play outside";    
       } 
       return "play inside";
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.