- 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
- 少兒人工智能趣味入門:Scratch 3.0動畫與游戲編程
- Rust編程:入門、實戰與進階
- 樂高機器人設計技巧:EV3結構設計與編程指導
- C語言最佳實踐
- 精通軟件性能測試與LoadRunner實戰(第2版)
- Python時間序列預測
- 精通MATLAB(第3版)
- 數據結構習題解析與實驗指導
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- Mastering C++ Multithreading
- Docker:容器與容器云(第2版)
- Python 快速入門(第3版)
- Visual Basic語言程序設計上機指導與練習(第3版)
- Spring Boot學習指南:構建云原生Java和Kotlin應用程序
- MySQL核心技術與最佳實踐