Command-line Calculator
Build a REPL calculator that reads expressions like 3 + 4 * 2, parses them (using when and string splitting), computes the result, and prints it. Practice basic syntax, control flow, and operator precedence.
Safe File Reader
Write a function that takes a nullable file path (String?), reads its contents if non-null, or returns a default message using ?:. Handle missing files without crashes.
Parameterized Greeting Service
Create a function greet(name: String = "Guest", punctuation: Char = '!') and implement a CLI that accepts named arguments (e.g. --name Alice --punctuation ?) to call it. Reinforce default/named parameters.
Number Categorizer
Read a list of integers from input, then use when with ranges to categorize each as “small” (1–10), “medium” (11–100), or “large” (101+). Print counts of each category. Exercises when, loops, and ranges.
Word Frequency Counter
Given a paragraph, split into words, then use a Map<String, Int> with filter, groupingBy, and eachCount() to compute how often each word appears. Sort and print the top 5. Practices collections and functional ops.
Count 1 to 10
Use a for loop to print numbers from 1 to 10. → Practice loops.
Find Largest of Three Numbers
Compare three numbers and print the largest. → Learn conditions and comparison.
Reverse a String
Ask for a word and print it backwards. → Practice strings and loops.
Check Palindrome
Ask for a word and check if it reads the same forward and backward. → Learn string operations.
List of Numbers
Create a list of numbers and print only the even ones. → Learn collections and filtering.
Square of Numbers
Make a list [1..5] and print each number squared. → Practice map function.
Student Class
Create a Student class with name and age, then print student info. → Learn classes.
Animal Sounds
Make a Dog and Cat class that inherit from Animal and override sound(). → Learn inheritance.
Simple Bank Account
Create a class with deposit() and withdraw() functions. → Practice encapsulation.
Lazy Greeting
Use by lazy to load a greeting message only when accessed. → Learn lazy delegation.
Extension Function
Add a function isPositive() to Int and test it. → Learn extension functions.
Box Class (Generics)
Create a Box<T> that can hold anything (Int, String). → Learn generics.
Data Class Person
Make a data class Person(val name: String, val age: Int) and use copy(). → Learn data classes.
Result with Sealed Class
Make sealed class Result with Success and Error. Print message using when. → Learn sealed classes.
Use Scope Functions
Create an object User("Alice", 20) and update age using apply. → Learn apply.