Skip to content

Commit

Permalink
Add Factorial in kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
fuslonflare committed Oct 4, 2018
1 parent 78de268 commit 2a62ad3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions code/mathematical_algorithms/src/factorial/Factorial.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package csd.gisc.hacktoberfest2018

import java.math.BigInteger
import java.util.*

/**
* Created by Phuwarin on 10/4/2018
* Part of Cosmos by OpenGenus
*/

object Factorial {

@JvmStatic
fun main(args: Array<String>) {
print("Enter a number: ")
val enterNum = Scanner(System.`in`)
val n = enterNum.nextLong()
println("Factorial is: " + factorial(n))
}

private fun factorial(n: Long): BigInteger {
var result = BigInteger.ONE
for (i in 1..n) {
result = result.multiply(BigInteger.valueOf(i))
}
return result
}
}

0 comments on commit 2a62ad3

Please sign in to comment.