输入50,输出包含3的数怎么输出

。。。。。。。。。。。
。。。。。。。。。。。

就是1-50之间带有3的数字么?


for(int i = 0;i<50;i++){
        int a = i%10;
        int b = i/10;
        if(a==3 || b==3){
            System.out.println(i);
        }

    }

用循环i++,判断余数呗


    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i <= 50; i++)
        {
            if (i%10==3)
                System.out.print(i +" ");
        }
    }

img

另外一种写法:

#include <stdio.h>
int main()
{
    int n, i, j;
    scanf("%d", &n);
    for (i = 0, j = 0; j * 10 + i <= n; ++i > 9 ? (i = 0, j++) : i)
        if (i == 3 || j == 3)
            printf("%d\n", j * 10 + i);
    return 0;
}