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