Ok first, please don't mark this down as a duplicate question. I know there are similar questions that explain it with specific strings, I need a "generic code" so to speak. I know how to do this with a given array, but I'm not sure how to do it for this assignment. It wants me to return the longest word in an array that is not present. But if for example there was an array of ["dog", "ostrich", "eagle"]
, it would return "ostrich"
.
public class Longest {
public static String longWord(String[] word) {
int array[] = [];
for (int i = 0; i < array.length; i++) {
if (word > current) {
return longWord;
}
}
}
}