搜狐笔试
搜狐java笔试第三题 比较版本号大小,本地没问题,提交就有问题,求大神看看代码,指出问题。不胜感激
import java.util.Scanner;
Scanner in = new Scanner(System.in);
String s1=in.next();
String s2=in.next();
// System.out.println(delete(s1));
System.out.println(test(delete(s1),delete(s2)));
}
public static int test(String a,String b){
int flag=0;
char[] aa=a.toCharArray();
char[] bb=b.toCharArray();
int i=0,j=0;
System.out.println(aa.length);
while(i<aa.length && i<bb.length){
if(aa[i]>bb[i]) {
flag=1;
break;
}
else if(aa[i]<bb[i]){
flag=-1;
break;
}
else{
System.out.println("****");
i++;
if(aa.length>bb.length){
flag=1;
}
else if(aa.length<bb.length){
flag=-1;
}
else{
flag=0;
}
}
}
return flag;
}
public static String delete(String s){
StringBuffer sb=new StringBuffer(s);
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)=='.'){
sb.deleteCharAt(i);
}
}
return sb.toString();
}
}
#笔试题目##搜狐#
import java.util.Scanner;
public class sh8 {public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s1=in.next();
String s2=in.next();
// System.out.println(delete(s1));
System.out.println(test(delete(s1),delete(s2)));
}
public static int test(String a,String b){
int flag=0;
char[] aa=a.toCharArray();
char[] bb=b.toCharArray();
int i=0,j=0;
System.out.println(aa.length);
while(i<aa.length && i<bb.length){
if(aa[i]>bb[i]) {
flag=1;
break;
}
else if(aa[i]<bb[i]){
flag=-1;
break;
}
else{
System.out.println("****");
i++;
if(aa.length>bb.length){
flag=1;
}
else if(aa.length<bb.length){
flag=-1;
}
else{
flag=0;
}
}
}
return flag;
}
public static String delete(String s){
StringBuffer sb=new StringBuffer(s);
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)=='.'){
sb.deleteCharAt(i);
}
}
return sb.toString();
}
}
#笔试题目##搜狐#