题目链接:Secret Number
计算出给定数各个位上数字为偶数的和。题目说明了在int范围里了。
只要每一位都判断一下是否%2==0
import java.util.Scanner;public class Main{private static Scanner scanner;public static void main(String[] args) {scanner = new Scanner(System.in);boolean boo = false;while(scanner.hasNext()){if(boo){System.out.println();}int n = scanner.nextInt();int sum = 0;while(n!=0){if((n%10)%2 == 0){//如果是偶数sum+= n%10;}n /= 10;}System.out.println(sum);boo = true;}}
}