代碼哪里出錯了
public class HelloWorld {
? ? public static void main(String[] args) {
int one = 20 ;
int a=one%2;
if(a==0){
? ? System.out.println("one為偶數");
? ??
? ? }elso{
? ? ?System.out.println("one為奇數");? ?
? ? }
? ??
? ??
}
}
public class HelloWorld {
? ? public static void main(String[] args) {
int one = 20 ;
int a=one%2;
if(a==0){
? ? System.out.println("one為偶數");
? ??
? ? }elso{
? ? ?System.out.println("one為奇數");? ?
? ? }
? ??
? ??
}
}
2022-08-28
舉報
2022-10-15
首先代碼中else拼寫錯誤,其次,正式開發中判斷是否為偶數最好是這樣,a != 0(a不等于0)因為要考慮到負數的情況
????????????????if(a!=0){
? ? System.out.println("one是偶數,"+a);
}else{
? ??
? ? System.out.println("one不是偶數,"+a);
}
2022-08-29
第二行代碼最后是“agrs"不是你寫的”args“
2022-08-28
else打錯了