こんにちは、スタックしています。次の問題を解決するには、どの方法が良いですか? 最も長いコメントをチェックまたは取得したいのですが、何かわかりませんか?
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");
}
}
どのコメントが最も長いかを確認したいので、アドバイスをお願いします