题解 | 7的倍数用求余,包含7用字符串的contains判

挑7

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int count = 0;
            String[] ary = new String[n];
            for(int i = 0;i < n;i++){
                if((i + 1) % 7 == 0){
                    count++;
                }else{
                    ary[i] = i + 1 + "";
                    //System.out.println(ary[i]);
                    if(ary[i].contains("7")){
                    count++;
                }

                }
            }

            System.out.println(count);
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务