Skip to main content

Practice Code Structure

Section 1.28 Identification

Activity 1.28.1.

    These code blocks are the ones you saw in the previous question and they all doing the same thing. Among these options which one is preferable?
  • public static boolean isLessThan23(int number) {
       if (number >= 23) {
            return false;
       } else {
            return true;
       } 
    }
    
  • This code can be improved!
  • public static boolean isLessThan23(int number) {
       if (!(number >= 23)) {
            return true;
       } else {
            return false;
       } 
    }
    
  • This code can be improved!
  • public static boolean isLessThan23(int number) {
       return !(number >= 23); 
    }
    
  • This code can be improved!
  • public static boolean isLessThan23(int number) {
       if (number < 23) {
            return true;
       } else { 
            return false;
       } 
    }
    
  • This code can be improved!
  • public static boolean isLessThan23(int number) {
       return number < 23; 
    }
    
  • Correct!
You have attempted 1 of 2 activities on this page.