HTML & JS
public static String LongestCommonPrefix(String[] str){
    String prefix = "";
    int min = str[0].length();

    for(int i=0; i<min; i++){
        for(int j=1; j<str.length; j++){
            if(str[0].charAt(i) != str[j].charAt(i)){
                return prefix;
            }
            min = Math.min(min, str[j].length());
        }
        prefix += str[0].charAt(i);
    }
    return prefix;
}

Generated URL:

Compile Errors :

prog.java:1: error: class, interface, or enum expected
public static String LongestCommonPrefix(String[] str){
              ^
prog.java:3: error: class, interface, or enum expected
    int min = str[0].length();
    ^
prog.java:5: error: class, interface, or enum expected
    for(int i=0; i
							

Output:

No Output
Report Bug