![](/img/trans.png)
[英]Java Error unexpected type required: variable; found: value in an ArrayList
[英]Java Error message. unexpected type, required variable, found value
我正在為其中一門課程進行調試。 我發現並修復了代碼中的一個錯誤。 我必須解決這個錯誤:
int input, x;
if ((input % 2)= 0) // <- this is the line with the error
++input;
else
--input;
我在input % 2
上遇到錯誤,這表示它正在尋找變量而不是值
這是因為賦值運算符(=)需要將一個變量分配給它的左側。 如果需要比較運算符以獲取布爾結果。 您應該使用==來表示相同的內容。 解決此問題后,您將面臨另一個問題,因為您嘗試使用局部變量(索引)而不進行初始化。
如果((input%2)== 0),則應使用== not =比較/檢查值
問題是等號“ =“。 此“ =”應替換為“ ==“。 這里是詳細說明https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
int input, x;
if ((input % 2) == 0)
++input;
else
--input;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.