Question: X 6 4 9 : Longest string Given an array of Strings, return the longest String in the array. If the array is empty, return

X649: Longest string
Given an array of Strings, return the longest String in the array. If the array is empty, return null.
Examples:
longest({"abc","ab","a"}) "abc"
Your Answer:
String longest(String[] names)
f
if (names. length ==0)
f
return -1 ;
line 5: error: incompatible types: int cannot be converted to java.lang.String
}
int max= numbers 0;
for (int i=1;i names. length; i++)
{
if (numbers [i]>max)
f
max= numbers i;
}
}
}
return max;
 X649: Longest string Given an array of Strings, return the longest

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!