← all categories
One Loop
-
weeksToPayOff 2.7 🌶️
You owe `balance` dollars on a loan and pay `weekly` dollars each week (a positive whole …
-
nextBusMinute 2.7 🌶️
A bus leaves the stop at minute `every`, then at `2 * every`, `3 * every`, and so on. You…
-
daysToFillJar 2.7 🌶️🌶️
You are filling a jar with coins to reach a `goal`. On day 1 you add 1 coin, on day 2 you…
-
Fix sumOddsUpTo 2.7 🌶️
The method below is supposed to return the sum of the odd numbers from 1 up to and includ…
-
caesarShiftString 2.7 🌶️🌶️🌶️
Write a method that takes one String parameter, s, and one int parameter, shift, and retu…
-
printSquares 2.8
Given n, print the square of each integer from 1 to n, one per line, using System.out.pri…
-
repeatText 2.8 🌶️
Your group chat needs a laugh. Write a method `repeatText` that takes a String `s` and an…
-
launchCountdown 2.8 🌶️
A rocket launch counts down out loud. Write a method `launchCountdown` that takes an int …
-
readathonPages 2.8 🌶️
In a read-a-thon you read as many pages as the day number: 1 page on day 1, 2 pages on da…
-
sumOfEvens 2.8 🌶️
Write a method `sumOfEvens` that takes an int `n` and returns the sum of the even numbers…
-
Fix addUpTo 2.8 🌶️
The method below is supposed to return the sum of the ints from 1 up to and including `n`…
-
factorial 2.8 🌶️
Write a method `factorial` that takes an int `n` (0 to 12) and returns `n!`: the product …
-
countMultiplesInRange 2.8 🌶️🌶️
Paydays come every `d` days, on day numbers that are multiples of `d` (including day 0). …
-
printTimesTable 2.8 🌶️
Write a method `printTimesTable` that takes an int `n` and prints the first ten lines of …
-
isPrime 2.9 🌶️🌶️
Write a method that takes one int parameter, n, and returns true if it's a prime number, …
-
countDigits 2.9 🌶️
Write a method that takes one int parameter, n, and returns how many digits it has. You c…
-
sumDigits 2.9 🌶️🌶️
Given a non-negative int n, return the sum of its digits. sumDigits(126) returns 9 (1+2+6…
-
isArmstrongNumber 2.9 🌶️🌶️🌶️
An Armstrong number is one where, if you raise each of its digits to the power of the TOT…
-
isBalancedParentheses 2.9 🌶️🌶️
Write a method that takes one String parameter, s, made up only of the characters '(' and…
-
pingPongPosition 2.9 🌶️🌶️
A scanner light sweeps back and forth along a strip of lights numbered `0` to `len`. It s…
-
isLuhnValid 2.9 🌶️🌶️🌶️
The Luhn algorithm is a checksum used to catch typos in card numbers. Write a method that…
-
binaryToDecimal 2.9 🌶️🌶️
A row of light switches is either on (`"1"`) or off (`"0"`). Read from left to right, the…
-
reverseString 2.10 🌶️
Write a method that takes one String parameter, s, and returns a new String with its char…
-
runLengthEncode 2.10 🌶️🌶️🌶️
Run-length encoding compresses a string by replacing each run of consecutive identical ch…
-
printRightTriangle 2.11 🌶️
Write a method that takes one int parameter, n, and prints a right triangle of asterisks …
-
printRectangle 2.11 🌶️
A sign painter marks out a rectangle with `#` characters. Write a method `printRectangle`…
-
printNumberTriangle 2.11 🌶️
Write a method `printNumberTriangle` that takes an int `n` (from 1 to 9) and prints `n` l…
-
countBlueTiles 2.11 🌶️
A gym floor is tiled in `rows` rows of `cols` tiles. The rows and columns are numbered fr…
-
handshakes 2.11 🌶️🌶️
At a meeting every person shakes hands once with every other person. Write a method `hand…
-
printPyramid 2.11 🌶️🌶️
Write a method that takes one int parameter, n, and prints a centered pyramid of asterisk…
-
countBalancedTimes 2.11 🌶️🌶️
A digital clock shows the hour and the minute, like 7:05 or 12:21. Call a time **balanced…
-
countBookendSubstrings 2.11 🌶️🌶️🌶️
A substring is a **bookend** when its first and last characters are the same letter. A si…
-
pythagoreanTriples 2.11 🌶️🌶️🌶️
A **Pythagorean triple** is three positive whole numbers `a < b < c` with `a * a + b * b …
-
printCheckerboard 2.11 🌶️🌶️
Write a method `printCheckerboard` that takes an int `n` and prints an `n` by `n` checker…
-
rotateArrayByN 4.5 🌶️🌶️
Write a method that takes an int array, nums, and an int, n, and returns a new int array …
-
capitalizeAll 4.9
Given an ArrayList<String> of words, return a new ArrayList<String> containing each word …
-
honorRoll 4.10 🌶️🌶️
Write a method that takes an ArrayList<Student> parameter, students, and returns an Array…