It produces the correct result. Can anyone advise on this or give me advice public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ArrayList<Integer> a = new ArrayList<Integer>(); int[] array = new int[20]; int maximum = 0; int minimum = 0; int index = 0; int min = array[0]; int max = array[0]; //get min of an array for (int i = 0; i < array.length; i++) { array[i] = Integer.parseInt(reader.readLine()); } for (int i = 0; i < array.length; i++) { if (array[i] < min){ min = array[i]; minimum = min; } } for (int i = 0; i < array.length; i++) { if (array[i] > max){ max = array[i]; maximum = max; } } System.out.print(maximum + " " + minimum); } }