Activity 1.24.1.
public static boolean canPlayGolf(String weather, int humidity, boolean isWindy) { if (weather.equals("Sunny")) { if (humidity < 60) { if (isWindy == false) { return true; } } } return false; }
- This code can be improved!
public static boolean canPlayGolf(String weather, int humidity, boolean isWindy) { if (weather.equals("Sunny") && humidity < 60 && !isWindy) { return true; } return false; }
- This code can be improved!
public static boolean canPlayGolf(String weather, int humidity, boolean isWindy) { return weather.equals("Sunny") && humidity < 60 && !isWindy; }
- Correct!
public static boolean canPlayGolf(String weather, int humidity, boolean isWindy) { if (!weather.equals("Sunny") || humidity >= 60 || isWindy) { return false; } return true; }
- This code can be improved!
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?