Summary - Operators
- Kotlin course
- Beginner
- Lesson 29/116
- 5 min
Combine arithmetic, logical and Elvis operators to build a grade calculator.
Summary - Operators
So far you've learned arithmetic, assignment, comparison, logical and Elvis operators. Each group serves a different purpose: arithmetic for calculations, assignment for changing values, comparison for conditions, logical for combining Booleans, Elvis for null handling.
These operators are the basic tools for writing calculations and conditions in code. Choosing the right operator makes code both shorter and more readable.
Practice Put it together
Write a fun main(). Declare val a = 10 and val b = 3. Print whether the remainder equals 1 with println(a % b == 1).
Sample solution
fun main() {
val a = 10
val b = 3
println(a % b == 1)
}Expected output
true
Next step
Congratulations! You've completed the operators group. You've learned all the fundamentals of the beginner level: program structure, variables, data types, the calculator project and operators.
In the next, intermediate level you'll focus on control flow, functions, classes and collections. With solid fundamentals, the intermediate level will feel much smoother.
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is a logical operator?
- && Correct answer
- +
- %
- ?:
Explanation: && is a logical operator.
2 Match the concepts
| Term | Meaning |
|---|---|
+ |
Addition |
== |
Equal |
&& |
And |
?: |
Elvis |
3 Summary - Operators: fill in the missing part
val name = input ____ "Guest"
val name = input ?: "Guest"
Explanation: With ?: you give a default for null values.