题解 | #挑7#

挑7

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

import java.util.*;

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        
        while(sc.hasNextInt()){
            int number = sc.nextInt();
            int result = 0;
            for(int i = 7; i <= number; i++){  
                if(isSeven(i) || i % 7 == 0){
                    result ++;
                }
            }
            System.out.println(result);
        }
    }
    
    public static boolean isSeven(int i){
 
        if(i == 7 || i % 10 == 7){
            return true;
        }else if(i != 0 && (i%10) != 7){
            return isSeven((i - i % 10)/10);
        }else{
            return false;
        }
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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