小编Vis*_*hal的帖子

Kotlin:必须初始化变量'result'

编译器显示错误Kotlin:result必须初始化变量.

这是代码.

fun main(args: Array<String>) {
    print("Enter two numbers: ")

    // nextDouble() reads the next double from the keyboard
    var first= readLine()!!.toDouble()
    var second = readLine()!!.toInt()

    print("Enter an choice(1-4)): ")
    val operator = readLine()!!.toInt()

    var result: Double

    when (operator) {
        1 -> result = first + second
        2 -> result = first - second
        3 -> result = first * second
        4 -> result = first / second

        else -> {
            println("Error.")
        }
    }

    println("The result is :- …
Run Code Online (Sandbox Code Playgroud)

kotlin

6
推荐指数
3
解决办法
7467
查看次数

标签 统计

kotlin ×1