题目
输入两个正整数a和b,输出整数区间[a,b]中任意含位3的数字。例如输入 39 49,则输出 39 43 。
分析
取出整数的每一位与3比对
39%10 -> 9
30/10 -> 3
3%10 -> 3
Java实现
public static void test02(){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
for (int i = a; i <=b ; i++) {
int n = i;
while (n > 0){
if (n % 10 == 3) {
System.out.print(i+ " ");
break;
}
n /= 10;
}
}
}