科大讯飞java?

是不是在搞啊,本地没问题啊
第一题0%
import java.util.*;

public class 把字符串中的数字拿出并排序 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String s1 = "";
        s = s.trim();
        if(s!=null){
            for(int i=0;i<s.length();i++){
                if(s.charAt(i)>=48&&s.charAt(i)<=57){
                    s1+= s.charAt(i);
                }
            }
        }

        int []num = new int[s1.length()];
        if("".equals(s1)){
            System.out.println(-1);
        }else {
            for (int i = 0; i < s1.length(); i++) {
                num[i] = Integer.parseInt(s1.substring(i, i + 1));
            }
            Arrays.sort(num);
            for (int i =0;i<num.length;i++) {
                System.out.println(num[i]);
            }
        }
    }

}
2.0%
import java.util.Scanner;

public class 递归方式找到数的位置 {
    public static void main(String[] args) {
        Scanner imput = new Scanner(System.in);
        int score[] = new int[6];
        for (int i = 0; i <= score.length - 1; i++) {
            score[i] = imput.nextInt();
        }

        int high = score.length-1 ;
        int low = 0;
        递归方式找到数的位置 main = new 递归方式找到数的位置();
        main.foundindex(score, high, low, 19);

    }

    public int foundindex(int score[], int high, int low, int n) {
        int mit = (high + low) / 2;
        if (low > high) {
            return -1;
        }
        if (n < score[mit]) {
            return found(score, mit - 1, low, n);
        } else if (n > score[mit]) {
            return found(score, high, mit + 1, n);
        } else if (n == score[mit]) {
            System.out.println(mit+1);
            return (mit+1);

        }

        return -1;

    }
}


#科大讯飞##笔试题目##Java#
全部评论
认真你就输了
点赞 回复
分享
发布于 2019-08-16 19:54

相关推荐

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