题解 | #挑7# java 模块设计【灵气Van】

挑7

https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b

// package hj;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int n = sc.nextInt();
        ans = find_7(n);
        System.out.println(ans);
    }
    public static int find_7(int n) {
        int ans = 0;
        for (int i = 1 ; i <= n ; i++) {
            if (has7(i) || i % 7 == 0) {
                ans++;
            }
        }
        return ans;
    }
    //todo it is useful
    public static boolean has7(int n) {
        while (n != 0) {
            if (n % 10 == 7) {
                return true;
            }
            n = n / 10;
        }
        return false;
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务