-5
public class evenVSodd
{
public static void main(String[] args)
{
int a;
a = 4;
if (a/2==0)
{
System.out.print("its an even number");
}
else
{
System.out.print("its a odd number");
}
}
}
結果是:程序沒有
----jGRASP exec: java evenVSodd
its a odd number
----jGRASP: operation complete.
'a/2'不是一個布爾類型。您可能想要添加一些比較運算符。它也不會正確檢查奇偶校驗。 'System.print.out'應該是'System.out.print'。 – Zong 2014-10-18 16:59:28
謝謝,但我仍然不能解決一個/ 2 是否有任何其他方式來解決這個錯誤 – 2014-10-18 17:04:52
你需要像'if(a/2 == 0)''不只是'如果(a/2)'''。另外,你可能想看看'%'(模)運算符。 – csmckelvey 2014-10-18 17:05:52