- Kotlin Programming By Example
- Iyanu Adelekan
- 183字
- 2021-08-27 20:00:05
Writing scripts with Kotlin
As previously stated, Kotlin can be used to write scripts. Scripts are programs that are written for specific runtime environments for the common purpose of automating the execution of tasks. In Kotlin, scripts have the .kts file extension appended to the file name.
Writing a Kotlin script is similar to writing a Kotlin program. In fact, a script written in Kotlin is exactly like a regular Kotlin program! The only significant difference between a Kotlin script and regular Kotlin program is the absence of a main function.
Create a file in a directory of your choosing and name it NumberSum.kts. Open the file and input the following program:
val x: Int = 1
val y: Int = 2
val z: Int = x + y
println(z)
As you've most likely guessed, the preceding script will print the sum of 1 and 2 to the standard system output. Save the changes to the file and run the script:
kotlinc -script NumberSum.kts
- C++程序設計(第3版)
- 深入淺出WPF
- PHP 編程從入門到實踐
- Java:High-Performance Apps with Java 9
- Linux C編程:一站式學習
- 計算機應用基礎項目化教程
- OpenMP核心技術指南
- Java Web應用開發項目教程
- Flask Web開發:基于Python的Web應用開發實戰(第2版)
- Building Slack Bots
- Julia High Performance(Second Edition)
- Python Machine Learning Cookbook
- Elasticsearch搜索引擎構建入門與實戰
- 精益軟件開發管理之道
- Web前端開發精品課:HTML5 Canvas開發詳解