about | help | code help+videos | done | prefs |
public boolean isSchoolDayA(int day)
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) |
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