zoukankan      html  css  js  c++  java
  • 字符串取最大值

    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]);
    }
    
     
    
    
    public static void main(String[] args) {
    String a = "1,54,2,57,8,7,232,112,9";
    String str1[] = a.split(",");
    Integer array[] = new Integer[str1.length];
    for(int i=0;i<str1.length;i++){
    array[i]=Integer.parseInt(str1[i]); 
    }
    List<Integer> l = Arrays.asList(array);
    TreeSet<Integer> tl = new TreeSet<Integer>(l);
    System.out.println("max-----------最大值"+tl.last());
    System.out.println("比最大值小的值--------"+tl.lower(tl.last()));//比最大值小的值
    }
    
     
  • 相关阅读:
    React-使用combineReducers完成对数据对拆分管理
    Linux
    Linux
    linux
    linux
    Linux
    Linux
    Linux
    Linux
    Linux 系统基础优化和常用命令
  • 原文地址:https://www.cnblogs.com/yy123/p/4097787.html
Copyright © 2011-2022 走看看