In: Computer Science
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] strings = new
String[100];
for (int i = 0; i <
strings.length; i++) {
System.out.println("Enter Strings: stop ");
strings[i]=input.nextLine();
if(strings[i].equalsIgnoreCase("stop"))
break;
}
MaxLength(strings);//here is the
error
}
public static int MaxLength(String[] array) {
int max = array[0].length();
for (int i = 0; i <
array.length; i++) {
if (max <
array[i].length())
max = array[i].length();
}
return max;
}
i'm getting error in the method solve it please .. the method is to
find the max length string
import java.util.Scanner; public class MaxArrayLength { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[] strings = new String[100]; for (int i = 0; i < strings.length; i++) { System.out.println("Enter Strings: stop "); strings[i] = input.nextLine().trim(); if (strings[i].equalsIgnoreCase("stop")) break; } System.out.println(MaxLength(strings)); } public static int MaxLength(String[] array) { int max = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i] != null && max < array[i].length()) max = array[i].length(); } return max; } }