笔试题1

2019-08-15  本文已影响0人  ShawnCaffeine

题目1

题目1
image.png

用StringBuilder来reverse 字符串?

public class Main {
    public static String t1(int input) {
        String binaryString = Integer.toBinaryString(input);
        StringBuilder a=new StringBuilder(binaryString);
        a.reverse();
        String b=""+a;
        int index =b.indexOf("101");
        if(index==-1){
            return 0+" "+index;
        }
        int count = 1;
        int start = 0;
        while (start < binaryString.length()) {
            start=start+3;
            if (binaryString.indexOf("101", start) >= 0) {
                count++;
            }
        }
return count+" "+index;
    }
    public static void main(String[] args) {
        System.out.println(t1(22));
    }
}

下面两题太难了

题目2

image.png
image.png
image.png

题目3

image.png
image.png
image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读