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

 

srp4379@lausd.net 3-stringbasics > isSummer
prev  |  next  |  chance

public boolean isSummer(String month) VERSION 2

The String method equals() is case-sensitive
i.e. capital and lowercase letters will not match.

There is a second version named equalsIgnoreCase() that
is case-INSENSITIVE.

If you use equalsIgnoreCase(), all of the following will match:
"June", "JUNE", "june" and even "JUne" and "juNE".

public boolean isSummer(String month) {
  boolean summer = false;
  if (month.equalsIgnoreCase("june")) {
    summer = true;
  }
  if (month.equalsIgnoreCase("JULY")) {
    summer = true;
  }
  if (month.equalsIgnoreCase("august")) {
    summer = true;
  }
  return summer;
}
Note that another way to code this, if you want to use equals()
is to use toLowerCase()
public boolean isSummer(String month) {
  boolean summer = false;
  month = month.toLowerCase();
  if (month.equals("june")) {
    summer = true;
  }
  if (month.equals("july")) {
    summer = true;
  }
  if (month.equals("august")) {
    summer = true;
  }
  return summer;
}

isSummer("JUNE") → true
isSummer("august") → true
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