diff --git a/out/production/kotlin-study-demo/META-INF/kotlin-study-demo.kotlin_module b/out/production/kotlin-study-demo/META-INF/kotlin-study-demo.kotlin_module index 4092a95..5af275f 100644 Binary files a/out/production/kotlin-study-demo/META-INF/kotlin-study-demo.kotlin_module and b/out/production/kotlin-study-demo/META-INF/kotlin-study-demo.kotlin_module differ diff --git a/out/production/kotlin-study-demo/basic/Main.class b/out/production/kotlin-study-demo/basic/Main.class index cb4a508..bb7fa11 100644 Binary files a/out/production/kotlin-study-demo/basic/Main.class and b/out/production/kotlin-study-demo/basic/Main.class differ diff --git a/out/production/kotlin-study-demo/basic/VariableKt.class b/out/production/kotlin-study-demo/basic/VariableKt.class new file mode 100644 index 0000000..1808b6a Binary files /dev/null and b/out/production/kotlin-study-demo/basic/VariableKt.class differ diff --git a/src/basic/variable.kt b/src/basic/variable.kt new file mode 100644 index 0000000..7236a2a --- /dev/null +++ b/src/basic/variable.kt @@ -0,0 +1,66 @@ +package basic + +import sun.rmi.runtime.Log + +/** + * 变量基础定义 + * 基本数据类型 Int Long Float Double String + * 关键字 var 可变变量 + * 关键字 val 不可变变量 + * 关键字 变量: 数据类型 = 默认值 + */ + +fun main() { + + /** + * 可变变量 + */ + + // 定义变量 声明变量类型 并初始化 + var a: Int = 1 + a += 6 + println(a) + + // 不声明类型 自动推断 + var b = 2L + println(b) + + // 未初始化变量值 必须声明变量类型 + var c: Int + c = 3 + println(c) + + // 打印拼接 + println("$a + $b + $c") + + /** + * 不可变变量(常量) + */ + + // 声明 初始化 + val d: Int = 123 + // 以下写法或报错 不可变变量不能二次赋值 + //d += 1 + println(d) + // 双精度整型 + val i: Long = 6L + println(i) + + // 自动推断类型 + val e = "rainerosion" + println(e) + + // 字符串 + val f: String + + // 单精度浮点数 + val g: Float = 3.1f + + // 双精度 浮点数 + val h: Double = 4.0 + println(h) + + // 不可变字符初始化 + f = g.toString() + print(f) +} \ No newline at end of file