java引用其他类的方法_java调用另一个类的方法

我正在处理一个问题,我很困难,因为我刚刚开始学习

java.任何帮助我可以理解这将是巨大的.我必须编写一个有两个类的程序.主类将从一个文件中读取并使用第二个类来查找文件中重复的相同单词的次数,并将它们添加到一个数组中,该数组包含该单词重复的单词和次数.我可以阅读文件部分.我似乎不能包围我的头,如何从第二类调用一个方法,将单词添加到数组中并递增计数器.

这是我的代码到目前为止如果你运行它,你会看到我有多新的错误,你会得到新的.

import java.io.*;

public class Words{

public static void main (String [] args)

{

ProcessInput();

System.out.println("\nprogram finished");

}

public static WordList ProcessInput( )

{

BufferedReader inputFile;

String inputLine;

String[] word;

WordList words;

try

{

inputFile=new BufferedReader(new FileReader ("inputFile.txt"));

inputLine = inputFile.readLine();

while (inputLine !=null)

{

word=inputLine.toLowerCase().split(" ");

for (int i=0; i

System.out.println (word[i]);

words=addWord(word[i]);

}

inputLine = inputFile.readLine();

}

inputFile.close();

}

catch (IOException ioe)

{

System.out.println (ioe.getMessage());

ioe.printStackTrace ();

}

return words;

}

}

class WordList {

String [] words;

int wordcount;

public WordList ( ){

words= new String [1000];

wordcount=0;

}

public String addWord (String word) {

words[wordcount]=word;

wordcount=+1;

return words[wordcount];

}

public void printList (){

for (int i=0; i

System.out.println (words[i]);

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值