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

 

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

public boolean isSchoolDayA(int day)

Given a number in the range 1-7 that represents a day of the week (1=Sunday, 2=Monday, etc.), return true if the day is M-F, false if it's the weekend.

Example 1:

  boolean schoolDay = false; // default: it's the weekend (1 || 7)
  if (2 <= day && day <= 6) {
    schoolDay = true;
  }
  return schoolDay;

Example 2:

  boolean schoolDay = true; // default: it's a weekday (2-6)
  if (day == 1 || day == 7) {
    schoolDay = false;
  }
  return schoolDay;
NOTE: When using an IF statement to decide between 1 or more possibilities:

(1) Declare a variable - of the type returned by the method -
     and assign it one of the possible values.

     For example, if the method is called:
     public String isSchoolDay(int day)
     you could declare a variable: String yesNo = "No";

     OR, if the method is called:
     public int isSchoolDay(int day)
     you could declare a variable: int sDay = 0;

(2) The last line will be a single return statement.
     It will return the value of the variable (the correct answer).

(3) In between the variable declaration (first line) and the return statement (last line),
     place one or more if statements to test the PARAMETER(s) for other possibilities.
     If an if statement is true, its body will modify the value of the return variable.

isSchoolDayA(1) → false
isSchoolDayA(2) → true
isSchoolDayA(3) → true

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

public boolean isSchoolDayA(int day) { }

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