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

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:

主站蜘蛛池模板: 霍邱县| 遵义市| 福清市| 九江县| 酒泉市| 当阳市| 永宁县| 宜兰市| 南昌市| 南澳县| 麻城市| 定结县| 汾西县| 霍山县| 睢宁县| 龙南县| 宿松县| 金坛市| 越西县| 梁平县| 突泉县| 岑溪市| 巧家县| 新兴县| 阿拉善右旗| 黄龙县| 安阳市| 吉木萨尔县| 莫力| 兴化市| 昌邑市| 从化市| 股票| 定南县| 荔浦县| 措勤县| 尚义县| 丰顺县| 嘉兴市| 邳州市| 大关县|