因此,我使用Twitter4j从Twitter收集了推文,将每个推文添加到名为状态的列表中,然后使用if语句和包含检查每个状态文本中的单词“ the”。如果为true,则将其添加到计数器,然后在最后显示计数器,但是即使tweet中的计数器也始终为0。代码如下:
for (Status status : statuses) {
String fullTweet = ((follower.getScreenName() + " - " + status.getCreatedAt() + " - " + status.getText()).replaceAll("\\n", "").replaceAll("\\r", ""));
System.out.println(fullTweet);
if (fullTweet.toLowerCase().contains("the")) {
the = the++;
}
}
答案 0 :(得分:0)
将您的增量写成the += 1
,而不是the = the++
,或者简单地写成the++
。
您要在增量前分配值,因为变量后有++是后增量。