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]);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值