I am trying to get the longest method to take a user-entered array of strings, and then return the element number of the longest string in this array. I brought it to such an extent that I was able to return the number of characters in the longest line, but I do not believe that this will work for what I need. My problem is that I get incompatible type errors all the time trying to figure this out. I still do not understand all the data type information with strings. It confuses me as I return to the array, but the array has strings. The main method is ok, I'm stuck on ???? part.
public static void main(String [] args)
{
Scanner inp = new Scanner( System.in );
String [] responseArr= new String[4];
for (int i=0; i<4; i++)
{
System.out.println("Enter string "+(i+1));
responseArr[i] = inp.nextLine();
}
int highest=longestS(responseArr);
}
public static int longestS(String[] values)
{
int largest=0
for( int i = 1; i < values.length; i++ )
{
if ( ????? )
}
return largest;
}
source
share