gpt4 book ai didi

java - 采取|| (或)语句作为输入?

转载 作者:行者123 更新时间:2023-12-03 02:40:18 27 4
gpt4 key购买 nike

我的类有一个 foo 方法和一个 main 方法,其中有一些变量和一个 print 语句。

public static boolean foo(int x, boolean b) {
if (x < 0) {
return true;
}
return !b;
}

假设我打印以下内容:

foo (-3, c || !c)

我无法理解 || 的含义应该做的。我在main中声明了boolean c = false,但我不知道它如何选择输入c(false)或!c(true)。另外,附带问题: boolean 变量前面的感叹号只会给出相反的结果,对吧?即,如果输入为 false,并且 foo 返回 !b,那么它会返回 true?

最佳答案

可以说,这是一个同义反复,始终正确。

c || !c 的意思是:“c OR not c”。其中之一始终是正确的。

关于java - 采取|| (或)语句作为输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13771403/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com