import java.io.*; public class EchoLongest extends Echo { // the current longest
ID: 3567391 • Letter: I
Question
import java.io.*;
public class EchoLongest extends Echo
{
// the current longest line
private String longest;
public EchoLongest (String datafile) throws IOException
{
super(datafile);
longest="";
}
// Sets the given line as the current longest if the line is
// longer than the value stored in the longest.
// Overrides the processLine method in Echo class
public void processLine(String line){
}
public void printLongest(){
System.out.print(longest);
} //end method
} //end class|
Fill in process line
Explanation / Answer
public void processLine(String line){String result = "";
StringTokenizer st = new StringTokenizer(line," ");
while(st.hasMoreTokens())
{
result = result+st.nextToken();
}
wordCount=st.countTokens();//contains no. of words
System.out.println(result);
/* while(wordCount < line.length()){
wordCount += line.length();
}*/
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.