官术网_书友最值得收藏!

Creating a simple Kotlin project

It's easy to create a Kotlin-JVM project using IntelliJ IDEA by observing the following steps:

  1. Click on File NewProject.
  2. In the New Project window, select Kotlin/JVM, and choose Next. This is shown in the following screenshot:

  1. In the next wizard, specify the Project name and the Project location. Choose JDK and Kotlin runtime and click on Finish.
  1. In the modules settings, click on Facets and add Kotlin to the module.
  2. We have now created a simple Kotlin project. We can write the code here in Kotlin:

     

  1. 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:

主站蜘蛛池模板: 濮阳县| 和田市| 武宁县| 会理县| 孟州市| 香港 | 贵定县| 赞皇县| 卫辉市| 万全县| 南部县| 榆树市| 延边| 万源市| 汕头市| 宝山区| 贡嘎县| 海丰县| 印江| 德江县| 沾益县| 泰兴市| 盐亭县| 通山县| 永善县| 乐安县| 京山县| 兴仁县| 中方县| 永州市| 浮梁县| 金寨县| 衡山县| 南乐县| 肥西县| 顺昌县| 万荣县| 班玛县| 澄迈县| 富平县| 惠水县|