你好我叠了哪一种方式可以很好的解决下面的问题?我想检查或检索最长的评论我不知道你有一些吗?
public class Day {
private Date date;
private int temperature;
private String comments ;
Weather weather;
Day( Date date, int temperature, String comments){
this.date=date;
this.temperature=temperature;
this.comments=comments;
}
public Date getDate(){
return date;
}
public void setDate(Date date){
this.date=date;
}
public int getTemperature(){
return temperature;
}
public void setTemperature(int temperature){
this.temperature=temperature;
}
public String getComments(){
return comments;
}
public void setComments(String comments){
this.comments=comments;
}
public Boolean longestComment(String longcom){
StringTokenizer st=new StringTokenizer(comments);
String s;
st.countTokens();
if(st.hasMoreTokens()){
return true;
}
return false;
}
public void testComent(String longcom){
if (longestComment(longcom)){
System.out.println("The longest comment is:" +longcom);
}
}
public static void main (String args []){
Calendar c=new GregorianCalendar();
Day day=new Day(c.getTime(),20,"Today is normal temperature");
day.testComent("Tomorrow is going to be the highest degree for ever in this summer");
day.testComent("Yesterday was the coldest temperature");
day.testComent("Next week is going to be the coldest temperature ever");
}
}
我想检查哪个评论是最长的请一些建议