public class Main
{
public static void main(String[] args) {
int x=8, y=0, z=1; //random integers
if (x > 0 && y < 0)
{
if (x==8)
System.out.print("Yes");
else if (z > 0)
System.out.print("No");
}
}
}
為什么這段代碼不列印輸出?
它應該列印“是”或“否”,因為第一個 if 是錯誤的?
uj5u.com熱心網友回復:
if (x > 0 && y < 0)
您的y值為 0,因此測驗y < 0回傳 false,您無需輸入第一個 if。
uj5u.com熱心網友回復:
&& 運算子僅當且僅當兩個運算元都為真時才回傳真即,
true && true = true
true && false = false
false && true = false
false && false = false
在您的代碼中,因為y= 0第一個 if 條件本身不滿足,所以您必須替換y<0為y<=0
uj5u.com熱心網友回復:
你應該這樣寫才能作業
public class Main { public static void main(String[] args) {
int x=8, y=0, z=1; //random integers
if (x > 0 && y < 0) System.out.print("Yes");
否則 if (z > 0) System.out.print("No");
}
}
uj5u.com熱心網友回復:
你應該改變這一行
if (x > 0 && y < 0)
對此
if (x > 0 && y <= 0)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/342782.html
標籤:爪哇
上一篇:如何在反應式編程中初始化一個空的MonoClass物件?
下一篇:在類建構式中使用列舉
