From 3e29efd27e234d6b5b384571dbd8a94f11bbba7a Mon Sep 17 00:00:00 2001 From: luming Date: Tue, 29 Jun 2021 14:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/basic/Func.kt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/basic/Func.kt diff --git a/src/basic/Func.kt b/src/basic/Func.kt new file mode 100644 index 0000000..febfc0f --- /dev/null +++ b/src/basic/Func.kt @@ -0,0 +1,29 @@ +package basic + +/** + * 函数 + * + */ +fun main(args: Array) { + println(getName("rainerosion")) + getAge(10) + println("sum = " + getSum(1,6)) +} + +/** + * 函数定义 + * fun 方法名(参数: 类型): 返回值类型 + */ + +// 函数定义 +fun getName(name: String): String { + return "name = $name" +} + +// 无返回值 +fun getAge(age: Int): Unit { + println("age = $age") +} + +// 单表达式函数 +fun getSum(a: Int, b: Int): Int = a + b \ No newline at end of file