id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

srp4379@lausd.net 1-logicbasics > isWinterMonth
prev  |  next  |  chance

public boolean isWinterMonth(int month)

Given a number in the range 1-12 that represents a month in the year (1=Jan, 2=Feb, etc), return true if WINTER occurs in that month, false otherwise. The months in which WINTER occurs are December-March.


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)

public boolean isWinterMonth(int month) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 1

Copyright Nick Parlante 2017 - privacy