Min and max problem >>>Java<<<
Hello, I'm doing the Minimum and Maximum problem from the Sorting Lists chapter and i don't know what is wrong and why SoloLearn is not certifying the problem as correct. (Test case 4 is still wrong). "The program you are given declares ArrayList of integers. Complete the program to take numbers as input and add them to ArrayList until its size isn't equal to 5. Then output its maximum and minimum values. Sample Input 4 12 3 88 96 Sample Output 96 3" My code is: import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[ ] args) { ArrayList<Integer> nums = new ArrayList<Integer>(); Scanner scanner = new Scanner(System.in); while(nums.size()<5){ int num = scanner.nextInt(); //your code goes here nums.add(num); } Collections.sort(nums,Collections.reverseOrder()); //your code goes here for (int s:nums){ if (s==Collections.max(nums) || s==Collections.min(nums)) System.out.println(s); } } }