
上QQ阅读APP看书,第一时间看更新
Creating a simple Kotlin project
It's easy to create a Kotlin-JVM project using IntelliJ IDEA by observing the following steps:
- Click on File | New | Project.
- In the New Project window, select Kotlin/JVM, and choose Next. This is shown in the following screenshot:
- In the next wizard, specify the Project name and the Project location. Choose JDK and Kotlin runtime and click on Finish.
- In the modules settings, click on Facets and add Kotlin to the module.
- We have now created a simple Kotlin project. We can write the code here in Kotlin:
- Under the source (src) directory, we can create the Kotlin files:
Now let's write a simple program to find the factorial of a number. Consider the following Factorial.kt file:
fun main(args: Array<String>) {
val number = 5
var factorial: Int = 1
for (i in 1..number) {
factorial *= i
}
println("Factorial of $number = $factorial")
}
The output is as follows: