1 /** 2 *Created by xuzili at 22:12 on 2018/4/4 3 */ 4 // 以上注释使用了IntelliJ Idea的File-Settings-Editor-Live Templates-User(Self)提供的/*a+tab键(自定义功能) 5 import java.util.*; 6 public class Main { 7 public static void main(String[] args) { 8 Scanner in=new Scanner(System.in); 9 System.out.println("Input x = "); 10 int x = in.nextInt(),n=0; 11 int[]y = new int[30]; 12 for (int i=0;x!=0;i++){ 13 y[n] = x%10; 14 x = x/10; 15 System.out.println("x的各位数为"+y[n++]); 16 } 17 int zero=0,odd=0,even=0; 18 for(int i=0;i<n;i++){ 19 if(y[i]==0) 20 zero++; 21 else 22 switch(y[i]%2){ 23 case 0:odd++;break; 24 case 1:even++;break; 25 } 26 } 27 System.out.println("奇数"+even); 28 System.out.println("偶数"+odd); 29 System.out.println("零"+zero); 30 } 31 }
Live Templates功能的具体使用请参考 https://blog.csdn.net/mhs624014469/article/details/76285258