Kotlin sin()
Published Oct 27, 2023
The math.sin() method in Kotlin’s math class is used to calculate the sine of an angle in radians.
Syntax
import kotlin.math.sin
val sineValue = sin(angle)
angle: The angle in radians for which you want to calculate the sine.
The math.sin() method returns a value of type Double representing the sine of the input angle.
Example
This example shows how to use the math.sin() method to calculate the sine of an angle:
import kotlin.math.*fun main() {val angle = PI / 6.0 // 30 degrees in radiansval sineValue = sin(angle)println("The sine of $angle radians is $sineValue.")}
This results in the following output:
The sine of 0.5235987755982989 radians is 0.49999999999999994.
Learn Kotlin on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours