I am trying to find the indexOf the longest string in the array, which is represented by the string longString. I keep getting a "cannot find symbol" error and have no clue how to fix this
public class Final21 {
public static String getLongString(String[] array) {
int x=0;
int maxLength = 0;
String longString = null;
for (String s : array) {
if (s.length() > maxLength) {
maxLength = s.length();
longString = s;
}
}
return longString;
}
public static String getShortString(String[] array) {
int minLength = 0;
String shortString = null;
for (String t : array) {
if (t.length() > minLength) {
minLength = t.length();
shortString = t;
}
}
return shortString;
}
public static void main(String[] args) {
String[] names = {"bob", "maxwell", "charley", "tomtomjack"};
String longString = getLongString(names);
System.out.println("The Longest String is: " + longString + " With The Index Of" + names.indexOf(longString));
String shortString = getShortString(names);
System.out.println("The Longest String is: " + shortString + " With The Index Of" );
}
}