首页 > 其他 > 详细

字符串取最大值

时间:2014-11-14 19:24:58      阅读:190      评论:0      收藏:0      [点我收藏+]

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]);
}

字符串取最大值

原文:http://www.cnblogs.com/yy123/p/4097787.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!