●Warmup-1 ●String-1 ●List-1 ●Logic-1 Warmup-1 1.sleep_in The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return True if we sleep in.sleep_in(False, ...
SametAtdagThisdocumentcontains44questionsinthesesections:●Warmup-1●String-1●List-1●Logic-1Warmup-11.sleep_inTheparameterweekdayisTrueifitisaweekday,andtheparametervacationisTrueifweareonvacation.Wesleepinifitisnotaweekdayorwe'reonvacation.ReturnTrueifwesleepin.sleep_in(False,False)→Truesleep_in...
1 2 3 4 public int powerN(int base, int n) { if (n == 0) return 1; return base * powerN(base, n - 1); } countX: 1 2 3 4 5 public int countX(String str) { if (str.length() == 0) return 0; if (str.charAt(0) == 'x') return 1 + countX(str.substring(1))...
1 2 3 4 5 6 7 public int scoreUp(String[] key, String[] answers) { int sum = 0; for (int i = 0; i < answers.length; i++) if (answers[i] == key[i]) sum += 4; else if (!answers[i].equals("?")) sum -= 1; return sum; } ...
●Warmup-2 ●Logic-2 ●String-2 ●List-2 Warmup-2 1.string_times Given a string and a non-negative int n, return a larger string that is n copies of the original string.string_times('Hi', 2) → 'HiHi'string_times('Hi', 3) → 'HiHiHi'string_times('Hi', 1) → 'Hi'
comparing my answers of the Codingbat problems to yours and I have learnt quite a bit form your examples. However, here I have to agree with Frank. You solution on “has12” is flawed. To quote: “if there is A 1 in the array with a 2 somewhere later” specifies a single possible ...