Q:

Java - To find the Second Highest Digit

I need to: 
Write a function that accepts a string and returns the second highest numerical digit in the input as an integer.
The following rules should apply:

Inputs with no numerical digits should return -1 
Inputs with only one    numerical digit should return -1 
Non-numeric characters should be    ignored 
Each numerical input should be treat individually, meaning in the
event of a joint highest digit then the second highest digit will
also be the highest digit

For example:

"abc:1231234" returns 3
"123123" returns 3

This is my code currently: 
public class Solution {
    public static int secondHighestDigit(String input) {

    try{

        int k = Integer.parseInt(input); 

        char[] array = input.toCharArray(); 

        int big = Integer.MIN_VALUE;
        int secondBig = Integer.MIN_VALUE;

        for(int i = 0; i < array.length; i++){

            System.out.println(array[i]);

            for(int n = 0; n < array[i]; n++){
                if(array[i] > big)
                {
                    secondBig = big;
                    big = array[i];
                }else if(array[i] > secondBig && array[i] != big){
                    secondBig = array[i];
                }
            }

        }

        System.out.println(secondBig);

        }catch(Exception e) {
        System.out.println("-1");
    }
    return -1;
    }

}

Tests:
import org.junit.*;
import static org.junit.Assert.*;

public class Tests
{

    @Test
    public void test1()
    {
        Solution solution = new Solution();

        assertEquals(3, solution.secondHighestDigit("abc:1231234"));
    }

    @Test
    public void test2()
    {
        Solution solution = new Solution();

        assertEquals(3, solution.secondHighestDigit("123123"));
     }
}

The program should print 3 for abc:1231234 and 123123 but instead it is returning -1 for both.
I am lost are where to go from here. I would be grateful if someone could help. Thanks.

A:

One possible solution is to remove all non numeric characters and sort the string
public int secondGreatest(String s) {
    String newStr = s.replaceAll("[^0-9]*", "");
    if (newStr.isEmpty() || newStr.length() == 1) {
        return -1;
    } else {
        char[] c = newStr.toCharArray();
        Arrays.sort(c);
        return c[newStr.length() - 2] - '0';
    }
}

