Kotlin sin()
Published Oct 27, 2023
Contribute to Docs
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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours