In the following tutorial, we’re going to understand how to perform basic maths operations and writing comments in between program in Kotlin.
- This tutorial assumes, you have a basic working knowledge of IntelliJ Idea.
- Have Kotlin installed setup in your machine.
- Follow the last tutorials for setting up a new class file before you can begin writing script.
Before we begin, we need to have a main function. This main function is called upon when the file is being executed, just like Java’s main function.
Declaring comments :
There are two ways to put comments in Kotlin.
- Using // for in-line comments.
- Using /**/ for comments spanning multiple lines.
In Kotlin, similar to Java, just use // to declare an in-line comment or /**/ to declare a multi-line comment.
Basic arithmetic operations
Types of numbers in Kotlin
Kotlin has 5 Arithmetic Operators, similar to Java, listed below :
- Addition operator (+)
- Subtraction operator (-)
- Multiplication operator (*)
- Division operator (/)
- Modulus operator (%)
var variable_one = variable_two + variable_three
var variable_one = variable_two - variable_three
var variable_one = variable_two * variable_three
var variable_one = variable_two / variable_three
var variable_one = variable_two % variable_three
Arithmetic Operations Example Program in Kotlin
Keep coding! Have fun.