思路:枚举+数字拆分

1.数字拆分:不断的%10,再/10

2.注意在枚举的过程中,用临时变量来代替i进行拆分

代码:
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int l = in.nextInt(),r = in.nextInt();
        int ret = 0;
        for (int i = l; i <= r; i++) {
            int tmp = i;
            while (tmp !=0) {
                if (tmp % 10 == 2) {
                   ret++;
                }
                tmp /= 10;
            }
        }
       System.out.println(ret);
    }
}