about | help | code help+videos | done | prefs |
public boolean isWinterMonth(int month)
Example 1: boolean winterMonth = false; // default if (1 <= month && month <= 3) { winterMonth = true; } if (month == 12) { winterMonth = true; } return winterMonth; Example 2: boolean winterMonth = false; // default // COMPOUND BOOLEAN expression !!! // NOTICE the INNER parentheses for the range Jan-March if ( month == 12 || (1 <= month && month <= 3) ) { winterMonth = true; } return winterMonth; COUNTER-EXAMPLE 3: boolean winterMonth = false; // default // COMPOUND BOOLEAN expression, INNER parentheses are INCORRECT! // THIS GIVES AN ERROR when month == 12 !!! if ( (month == 12 || 1 <= month) && month <= 3 ) { winterMonth = true; } return winterMonth; IMPORTANT: When a COMPOUND boolean expression mixes && (AND) and || (OR), ALWAYS use INNER parentheses to group the different expressions!!! isWinterMonth(1) → true isWinterMonth(2) → true isWinterMonth(3) → true ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 1
Copyright Nick Parlante 2017 - privacy