https://github.com/shobhakartiwari/kotlinplayground
This is used to write code in kotlin
https://github.com/shobhakartiwari/kotlinplayground
Last synced: 2 months ago
JSON representation
This is used to write code in kotlin
- Host: GitHub
- URL: https://github.com/shobhakartiwari/kotlinplayground
- Owner: shobhakartiwari
- Created: 2023-10-09T03:00:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-09T03:03:56.000Z (over 1 year ago)
- Last Synced: 2023-10-09T04:21:18.716Z (over 1 year ago)
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KotlinPlayground
This is used to write code in kotlin
```
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
println("Hello, world!!!")
val result = sumOfTwoNum(1, 3)
println("sum = $result")
val a : Int = 1
val sum = sumOfOptionalNum(a,a)
println("sum = $sum")
val array = arrayOf("1","2","3","4","5","6")
val evenSum = sumOfEvenfrom(array)
println("total sum of even = $evenSum")
}// function to find the sum of two number
fun sumOfTwoNum(n1:Int, n2:Int) : Int {
val result = n1 + n2
return result
}// function to find the sum of two optional numbers
fun sumOfOptionalNum(a: Int?, b: Int?): Int {
return (a ?: 0) + (b ?: 0)
}//find the sum of even numbers from an array of string
fun sumOfEvenfrom(stringArray:Array) : Int {
val intArray = stringArray.map{it.toInt()}
val evenArray = intArray.filter{it % 2 == 0}
val sum = evenArray.reduce{acc, element -> acc + element}
return sum
}
```