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

 

srp4379@lausd.net > isSummer
prev  |  next  |  chance

public boolean isSummer(String month)

Given the name of a month, determine whether it is a summer month
("June", "July" or "August"). If it is, return true. Otherwise return false.

Although startsWith() can be used to solve many problems,
occasionally it is not the best choice.

Sometimes the best choice is equals(), as for this problem.

public boolean isSummer(String month) {
  boolean summer = false;
  if (month.equals("June")) {
    summer = true;
  }
  if (month.equals("July")) {
    summer = true;
  }
  if (month.equals("August")) {
    summer = true;
  }
  return summer;
}
NOTE: that if you have 3 successive IF statements, they can be
collapsed into a single statement if you separate them with || (OR).
public boolean isSummer(String month) {
  boolean summer = false;
  if ( month.equals("June") || month.equals("July") || month.equals("August") ) {
    summer = true;
  }
  return summer;
}



isSummer("January") → false
isSummer("February") → false
isSummer("March") → false

...Save, Compile, Run (ctrl-enter)

public boolean isSummer(String 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