outputResult()方法中的三进制在传递字符时停止按预期运行

问题描述 投票:-1回答:1

我一直在提取方法,但不确定这里发生了什么。当我将char传递给outputResult()时,三进制停止按预期运行,并且看起来总是等于true。

public static void outputResult(int value, char letter){
        ifElse(value);

        System.out.println(switchNumber(value) == -1 ? "Switch value was out of range." +
                " Value = " + value:switchNumber(value));

        switchChar(letter);
}

完整的代码有问题:https://gist.github.com/thinkexe/6999296fe4339baa748061c5d7d4ae16

java methods ternary
1个回答
0
投票

如果您查看代码,则如果有任何数字,您将从switchNumber(value)方法返回-1。现在在三元运算符中,您正在将结果与-1进行比较,这是正确的。因此,您对于三元方程式是正确的,并且接下来的语句将执行,这就是为什么您<。然后,调用方法switchChar(letter)后,该方法将以您的字母为'A'

回复您
© www.soinside.com 2019 - 2024. All rights reserved.