Sign up
Log in
Home
Language tracks
Java track
Exercises
Exercises on the Java track
Join the Java Track
110 exercises to help you master Java
easy
Hello World
The classical introductory exercise. Just say "Hello, World!"
strings
easy
Two Fer
Create a sentence of the form "One for X, one for me."
conditionals
strings
easy
Reverse String
Reverse a string
strings
easy
Resistor Color
Convert a resistor band's color to its numeric representation
arrays
strings
easy
Darts
Write a function that returns the earned points in a single toss of a Darts game
games
easy
Armstrong Numbers
Determine if a number is an Armstrong number
integers
math
easy
RNA Transcription
Given a DNA strand, return its RNA Complement Transcription.
loops
maps
strings
easy
D&D Character
Randomly generate Dungeons & Dragons characters
game
integers
randomness
easy
Pangram
Determine if a sentence is a pangram.
pattern matching
regular expressions
strings
easy
Hamming
Calculate the Hamming difference between two DNA strands.
integers
loops
strings
easy
Gigasecond
Given a moment, determine the moment that would be after a gigasecond has passed.
dates
integers
time
easy
Space Age
Given an age in seconds, calculate how old someone is in terms of a given planet's solar years.
conditionals
floating point numbers
easy
Acronym
Convert a long phrase to its acronym
loops
parsing
searching
strings
easy
Scrabble Score
Given a word, compute the scrabble score for that word.
games
loops
pattern matching
strings
transforming
easy
Raindrops
Convert a number to a string, the contents of which depend on the number's factors.
conditionals
integers
strings
easy
Difference Of Squares
Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.
integers
loops
math
easy
Secret Handshake
Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.
bitwise operations
conditionals
cryptography
enumerations
integers
loops
transforming
easy
Perfect Numbers
Determine if a number is perfect, abundant, or deficient based on Nicomachus' (60 - 120 CE) classification scheme for natural numbers.
enumerations
exception handling
filtering
integers
math
easy
Protein Translation
Translate RNA sequences into proteins.
arrays
conditionals
loops
strings
medium
Yacht
Score a single throw of dice in the game Yacht
enumerations
filtering
games
pattern matching
sorting
medium
Proverb
For want of a horseshoe nail, a kingdom was lost, or so the saying goes. Output the full text of this proverbial rhyme.
arrays
loops
strings
medium
ISBN Verifier
Check if a given string is a valid ISBN-10 number.
integers
loops
strings
medium
Sum Of Multiples
Given a number, find the sum of all the multiples of particular numbers up to but not including that number.
arrays
conditionals
integers
loops
math
medium
Luhn
Given a number determine whether or not it is valid per the Luhn formula.
algorithms
booleans
loops
strings
type conversion
medium
Matrix
Given a string representing a matrix of numbers, return the rows and columns of that matrix.
arrays
integers
loops
pattern matching
strings
type conversion
medium
Triangle
Determine if a triangle is equilateral, isosceles, or scalene.
booleans
classes
exception handling
medium
Largest Series Product
Given a string of digits, calculate the largest product for a contiguous substring of digits of length n.
integers
loops
strings
type conversion
math
medium
Sieve
Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.
algorithms
integers
lists
loops
math
medium
Twelve Days
Output the lyrics to 'The Twelve Days of Christmas'
arrays
conditionals
loops
strings
medium
Rotational Cipher
Create an implementation of the rotational cipher, also sometimes called the Caesar cipher.
cryptography
integers
strings
medium
Kindergarten Garden
Given a diagram, determine which plants each child in the kindergarten class is responsible for.
arrays
enumerations
lists
logic
loops
pattern recognition
strings
medium
Collatz Conjecture
Calculate the number of steps to reach 1 using the Collatz conjecture
conditionals
exception handling
integers
recursion
math
medium
Nth Prime
Given a number n, determine what the nth prime is.
arrays
exception handling
integers
lists
loops
math
medium
Saddle Points
Detect saddle points in a matrix.
arrays
conditionals
integers
lists
loops
matrices
sets
medium
Error Handling
Implement various kinds of error handling and resource management
exception handling
optional values
medium
Diamond
Given a letter, print a diamond starting with 'A' with the supplied letter at the widest point.
arrays
lists
loops
strings
text formatting
medium
Isogram
Determine if a word or phrase is an isogram.
conditionals
loops
parsing
strings
medium
Variable Length Quantity
Implement variable length quantity encoding and decoding.
bitwise operations
conditionals
exception handling
lists
loops
transforming
medium
Flatten Array
Take a nested list and return a single list with all values except nil/null
arrays
lists
loops
recursion
medium
Pig Latin
Implement a program that translates from English to Pig Latin
arrays
lists
strings
transforming
medium
Phone Number
Clean up user-entered phone numbers so that they can be sent SMS messages.
conditionals
pattern matching
regular expressions
strings
medium
Nucleotide Count
Given a DNA string, compute how many times each nucleotide occurs in the string.
conditionals
exception handling
integers
maps
parsing
searching
strings
medium
Word Count
Given a phrase, count the occurrences of each word in that phrase.
conditionals
integers
loops
maps
strings
medium
Run Length Encoding
Implement run-length encoding and decoding.
integers
pattern matching
strings
transforming
medium
Robot Name
Manage robot factory settings.
pattern matching
randomness
regular expressions
strings
text formatting
medium
Prime Factors
Compute the prime factors of a given natural number.
arrays
conditionals
integers
lists
loops
math
medium
Allergies
Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
booleans
conditionals
enumerations
integers
lists
loops
medium
Bob
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
booleans
conditionals
strings
medium
Pascal's Triangle
Compute Pascal's triangle up to a given number of rows.
algorithms
arrays
exception handling
integers
matrices
math
medium
Matching Brackets
Make sure the brackets and braces all match.
stacks
strings
medium
Series
Given a string of digits, output all the contiguous substrings of length `n` in that string.
conditionals
lists
loops
strings
type conversion
medium
Atbash Cipher
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
cryptography
security
strings
medium
Grep
Search a file for lines matching a regular expression pattern. Return the line number and contents of each matching line.
files
filtering
pattern matching
searching
strings
medium
Alphametics
Write a function to solve alphametics puzzles.
conditionals
logic
medium
Spiral Matrix
Given the size, return a square matrix of numbers in spiral order.
arrays
integers
loops
matrices
medium
Roman Numerals
Write a function to convert from normal numbers to Roman Numerals.
integers
logic
loops
maps
strings
medium
Transpose
Take input text and output it transposed.
arrays
lists
loops
matrices
strings
text formatting
medium
House
Output the nursery rhyme 'This is the House that Jack Built'.
arrays
conditionals
loops
strings
text formatting
medium
Food Chain
Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'
arrays
lists
strings
medium
Beer Song
Produce the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
conditionals
loops
strings
text formatting
variables
medium
Queen Attack
Given the position of two queens on a chess board, indicate whether or not they are positioned so that they can attack each other.
arrays
classes
conditionals
games
matrices
medium
ETL
We are going to do the `Transform` step of an Extract-Transform-Load.
lists
maps
transforming
medium
Grade School
Given students' names along with the grade that they are in, create a roster for the school
conditionals
lists
maps
sorting
strings
medium
Robot Simulator
Write a robot simulator.
classes
enumerations
logic
loops
medium
Binary Search
Implement a binary search algorithm.
arrays
recursion
searching
medium
Minesweeper
Add the numbers to a minesweeper board
conditionals
games
integers
lists
matrices
strings
medium
Wordy
Parse and evaluate simple math word problems returning the answer as an integer.
exception handling
integers
logic
parsing
pattern matching
regular expressions
strings
transforming
medium
All Your Base
Convert a number, represented as a sequence of digits in one base, to any other base.
arrays
conditionals
exception handling
integers
loops
math
medium
Bank Account
Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!
concurrency
exception handling
integers
medium
Bowling
Score a bowling game
conditionals
exception handling
games
integers
medium
Linked List
Implement a doubly linked list
algorithms
generics
lists
medium
Tournament
Tally the results of a small football competition.
loops
maps
parsing
sorting
text formatting
medium
Parallel Letter Frequency
Count the frequency of letters in texts using parallel computation.
concurrency
maps
strings
medium
Rail Fence Cipher
Implement encoding and decoding for the rail fence cipher.
conditionals
loops
strings
medium
Affine Cipher
Create an implementation of the Affine cipher, an ancient encryption algorithm from the Middle East.
cryptography
security
strings
text formatting
medium
Two Bucket
Given two buckets of different size, demonstrate how to measure an exact number of liters.
algorithms
conditionals
loops
medium
Zebra Puzzle
Solve the zebra puzzle.
logic
medium
Anagram
Given a word and a list of possible anagrams, select the correct sublist.
arrays
conditionals
equality
lists
loops
strings
medium
Sublist
Write a function to determine if a list is a sublist of another list.
enumeration
generics
lists
loops
searching
medium
Word Search
Create a program to solve a word search puzzle.
games
logic
matrices
pattern matching
searching
strings
medium
Simple Linked List
Write a simple linked list implementation that uses Elements and a List
algorithms
exception handling
generics
lists
medium
Binary Search Tree
Insert and search for numbers in a binary tree.
generics
graphs
searching
sorting
trees
medium
Meetup
Calculate the date of meetups.
conditionals
dates
enumerations
loops
medium
Crypto Square
Implement the classic method for composing secret messages called a square code.
cryptography
lists
security
strings
text formatting
medium
Markdown
Refactor a Markdown parser
conditionals
pattern matching
refactoring
strings
medium
Poker
Pick the best hand(s) from a list of poker hands.
games
parsing
sorting
medium
Clock
Implement a clock that handles times without dates.
equality
integers
logic
object oriented programming
strings
time
medium
Zipper
Creating a zipper for a binary tree.
integer
links
nodes
tree
medium
Go Counting
Count the scored points on a Go board.
algorithms
conditionals
games
loops
medium
Dominoes
Make a chain of dominoes.
algorithms
exception handling
games
lists
hard
OCR Numbers
Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.
exception handling
lists
loops
parsing
strings
hard
Circular Buffer
A data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
classes
exception handling
queues
hard
Rectangles
Count the rectangles in an ASCII diagram.
arrays
logic
pattern recognition
strings
hard
Book Store
To try and encourage more sales of different books from a popular 5 book series, a bookshop has decided to offer discounts of multiple-book purchases.
algorithms
floating point numbers
integers
lists
hard
Diffie Hellman
Diffie-Hellman key exchange.
algorithms
integers
transforming
math
hard
Simple Cipher
Implement a simple shift cipher like Caesar and a more secure substitution cipher
cryptography
exception handling
randomness
security
strings
hard
Complex Numbers
Implement complex numbers.
floating point numbers
math
hard
Rational Numbers
Implement rational numbers.
algorithms
floating point numbers
math
hard
List Ops
Implement basic list operations
filtering
functional programming
generics
lists
loops
hard
Change
Correctly determine change to be given using the least number of coins
algorithms
exception handling
integers
lists
hard
Palindrome Products
Detect palindrome products in a given range.
conditionals
integers
lists
loops
maps
math
hard
Pythagorean Triplet
There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product a * b * c.
integer
lists
logic
math
hard
Forth
Implement an evaluator for a very simple subset of Forth
exception handling
lists
logic
parsing
stacks
strings
hard
Custom Set
Create a custom set type.
equality
generics
sets