题目1
题目1image.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.pngimage.png
image.png
题目3
image.pngimage.png
image.png
image.png
网友评论