find 2nd max no. in an array
Anonymous
Integer[] array = new Integer[]{1, 2, 3, 3, 3, 4, 4, 3, 2, 0}; Integer first = array[0]; Integer second = array[0]; for( Integer num : array ){ if ( num > first ){ second = first; first = num; } if ( num < first && first == second ) second = num; } System.out.println(second);
Check out your Company Bowl for anonymous work chats.