
WAP to accept 10 strings from the user and find out the string with maximum length and print the same.

Here is a code that accepts 10 strings from the string and stored into array and then find the string with the maximum length.
import java.util.*;
class StringExample{
public static String compare(String st1, String st2){
if(st1.length()>st2.length()){
return st1;
}
else{
return st2;
}
}
public static void main(String []args){
String word = "";
Scanner input=new Scanner(System.in);
String stringArray[] = new String[10];
System.out.println("Enter strings: ");
for(int i=0;i<stringArray.length;i++){
stringArray[i]=input.nextLine();
}
for(int i=0;i<stringArray.length;i++){
if(i==0){
word = stringArray[0];
}
word = compare(word, stringArray[i]);
}
System.out.println("String with Maximum Length= " + word);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.