
Write a program in java and accept 10 strings form the user. store them in an array. then find the string with the maaximum length and print it.

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("Longest word = " + 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.