京东8月6日Java开发笔试

1.数组求和
package Test.Jd2;

import java.util.Scanner;

public class jd1 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        double sum = 0;
        for(double i = 1; i <= n; i++ ){
            sum += (double) 1/((double)5 * ((double)2 * i - (double)1)) - (double)1/((double)5 * ((double)2 * i));
        }
        String result =  String.format("%.4f", sum);
        System.out.println(result);
    }
}
2.回文素数
package Test.Jd2;

import java.util.Scanner;

public class jd2 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        int count = 0;
        for(int i = m; i <= n; i++){
            String s = String.valueOf(i);
            for(int j = s.length() - 1; j >= 0; j--){
                String temp = s.substring(0,j) + s.substring(j+1,s.length());
                int a = Integer.parseInt(temp);
                //System.out.println(a);
                if(isPalindrome(a)){
                    if(isPrime(a)){
                        count++;
                        break;
                    }
                }
            }
        }
        System.out.println(count);
        //System.out.println(isPrime(1));

    }
    public static boolean isPalindrome(int x) {
        char[] chars=String.valueOf(x).toCharArray();
        int left=0;
        int right=chars.length-1;
        while (left<=right){
            if(chars[left++]!=chars[right--]){
                return false;
            }
        }
        return true;
    }
    //判断是不是素数
    public static boolean isPrime(int x) {
        int i = 2;
        for(;i<x;i++) {
            if (x % i == 0) {
                break;
            }
        }
        if(x == i){
            return true;
        }
        return false;
    }

}


#京东##Java工程师#
全部评论
请教一下第二题题目是什么呀?
点赞 回复 分享
发布于 2020-08-27 15:30

相关推荐

愤怒的查理被升职:每个项目经历后面加关键成果:xxx, 项目经历要和岗位JD匹配,不是有多少项目经历都要写上的,挑选出是个岗位JD的,并且内容往岗位JD方面写,教育背景直接写 大学+专业+时间,一行就过去了。你是建筑投运营别人不看你本科建筑学的怎么样
点赞 评论 收藏
分享
评论
2
4
分享

创作者周榜

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