用于表中字数计数的Java程序

时间:2015-06-03 07:53:25

标签: java

我编写的Java代码可以找到表中的no.of单词。

它在循环中工作,但一旦退出循环,该值就变为0。

请帮助我获得正确的价值。

int f=0;
int fc=0;
Statement sta4=connection.createStatement();
ResultSet rs4=sta4.executeQuery("select * from db1");
while(rs4.next())
{
    word[f]=rs4.getString(1).replace("$", "");
    System.out.println(" sentece ="+word[f]);
    fc= countWords(word[f]);
    System.out.println("The sentence has "+ fc + " words");
    f++;
}
System.out.println(" count  =" + fc);

1 个答案:

答案 0 :(得分:0)

int f=0;
int fc=0;
Statement sta4=connection.createStatement();
ResultSet rs4=sta4.executeQuery("select * from db1");
while(rs4.next())
{
    word[f]=rs4.getString(1).replace("$", "");
    System.out.println(" sentece ="+word[f]);
    int fcTemp= countWords(word[f]);
    System.out.println("The sentence has "+ fcTemp + " words");
    fc += fcTemp;
    f++;
}
System.out.println(" count  =" + fc);

使用它。你没有加fc