Java Minimum and Maximum values in Array

前端 未结 13 979
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 06:32

My code does not give errors, however it is not displaying the minimum and maximum values. The code is:

Scanner input = new Scanner(System.in);

int array[]          


        
13条回答
  •  天命终不由人
    2020-12-01 07:12

    Imho one of the simplest Solutions is: -

    //MIN NUMBER
    Collections.sort(listOfNumbers);
    listOfNumbers.get(0);
    
    //MAX NUMBER
    Collections.sort(listOfNumbers);
    Collections.reverse(listOfNumbers);
    listOfNumbers.get(0);
    

提交回复
热议问题