写的可能不好,但是能达到要求! public class Test0 { public static void main(String[] args) { int a=12345; int countj=0,counto=0; for(int i=0;i<5;i++){ int n=1; for(int j=0;j<4-i;j++){ n*=10; } if(a/n%2==0)counto++; else countj++; } System.out.println ("奇数:"+countj+"偶数:"+counto); } }
public class Test0 { public static void main(String[] args) { int a=12345; int countj=0,counto=0; int n=1; for(int j=0;j<=5;j++){ if(a/n%2==0)counto++; else countj++; n*=10; } System.out.println ("奇数:"+countj+"偶数:"+counto); } } 这样也应该可以,没有编译器。 不对别笑话啊!
给你一个可以判断任何位数的int整数的程序吧public class TestNumber{ public static void main(String[] args){ int n=12345678; int ceven=0,codd=0; while(n!=0){ ceven+=(n%10%2==0)?1:0; codd+=n%10%2; n/=10; } System.out.println("Even : "+ceven+" , Odd : "+codd); } }
public class Test0 {
public static void main(String[] args) {
int a=12345;
int countj=0,counto=0;
for(int i=0;i<5;i++){
int n=1;
for(int j=0;j<4-i;j++){
n*=10;
}
if(a/n%2==0)counto++;
else countj++;
}
System.out.println ("奇数:"+countj+"偶数:"+counto);
}
}
public static void main(String[] args) {
int a=12345;
int countj=0,counto=0;
int n=1;
for(int j=0;j<=5;j++){
if(a/n%2==0)counto++;
else countj++;
n*=10;
}
System.out.println ("奇数:"+countj+"偶数:"+counto);
}
}
这样也应该可以,没有编译器。
不对别笑话啊!
public static void main(String[] args){
int n=12345678;
int ceven=0,codd=0;
while(n!=0){
ceven+=(n%10%2==0)?1:0;
codd+=n%10%2;
n/=10;
}
System.out.println("Even : "+ceven+" , Odd : "+codd);
}
}