首页 > 代码库 > 字符串取最大值

字符串取最大值

public static void main(String args[]){
String s = "3,2,4,2,5,2,6,45,7,54444,8655,5,45,3,867";
String[] objs = s.split(",");
String temp = null;
for(int i=0;i<objs.length;i++){
for(int j=i+1;j<objs.length;j++){
if(Integer.parseInt(objs[i]) < Integer.parseInt(objs[j])){
temp = objs[i];
objs[i]=objs[j];
objs[j]=temp;
}
}
}

System.out.println("-最小值"+objs[objs.length-1]+"------------最大值----"+objs[0]);
}

 

 

 

 

 

 

 

 

 

 

 

@org.junit.Test
public void max2(){
String a = "1,54,2,57,8,7,232,112,9";
String str1[] = a.split(",");
int array[] = new int[str1.length];
for(int i=0;i<str1.length;i++){
array[i]=Integer.parseInt(str1[i]);
}
Arrays.sort(array);
System.out.println("max---------最大"+array[array.length-1]+"----------------------最小"+array[0]);
}

字符串取最大值