
write a method that takes and return an object of your own type?

Hi Friend,
Try the following code:
class TakeAndReturnObject{
public static String getLargestWord(String st){
String[] str = st.split(" ");
String longest = str[0];
for(String s : str){
if(s.length() > longest.length()){
longest = s;
}
}
return longest;
}
public static void main(String[] args){
String str="All glitters are not gold";
String longestword=getLargestWord(str);
System.out.println(longestword);
}
}
Thanks
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.