关于字数统计的小问题,我的程序只能查奇数行-已解决 (50分)

  • 主题发起人 主题发起人 nickwuu
  • 开始时间 开始时间
N

nickwuu

Unregistered / Unconfirmed
GUEST, unregistred user!
[:)] 大家好,我在写一个统计字数和特定词的程序。 下面的是main method, 我还没有联接其他的class。 下面这个程序有点问题,只能统计奇数行,请大家帮忙看下,谢谢
另外还有一个问题,就是下面这个程序怎么与其他class最好的相连,包括一个数词class,一个数句子class,还有一个信息的vector。
代码:
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;
public class main
{
	public static void main(String[] args) throws IOException
	                                            ,FileNotFoundException
	{
		StringTokenizer tokenizer;
		String fileAddress;
 //the address of the file
		String addressInput;
//the file name entered by the user 
        String s;
//the token
		int lineNo;
//the number of lines in the text
        int i;
        int counter;
//the number of all the words in the text
       // TokenCounter tokenCounterA;

 addressInput = JOptionPane.showInputDialog("Enter the file name:");

// while loop starts, prompt the user to input the file name, and the whole 
// program starts.. when the program ends, prompt the user to enter a new file 
// name or enter nothing to terminate the program 
while(addressInput.length() > 0)
{
	fileAddress = "h://" + addressInput;
    BufferedReader inFile =
		                new BufferedReader(new FileReader(fileAddress));

   tokenizer = new StringTokenizer(inFile.readLine());
   s = tokenizer.nextToken();
   lineNo = 1;
   counter = 0;
  while (s.length() > 0)
  {
    counter++;
	System.out.println("Line" + lineNo + ": " + s  );
    if(tokenizer.hasMoreTokens())
    s = tokenizer.nextToken();
    
    else
    
    {
	 if(inFile.readLine() != null)
	  {
	   tokenizer = new StringTokenizer(inFile.readLine());
       lineNo++;
      }
     else
     s = "";
     }
 }
System.out.println("All words:" + counter);
//prompt the user to enter another file name
addressInput = JOptionPane.showInputDialog("Enter the file name:");
}//while loop ends
//terminate the program
System.exit(0);
   }

}

已解决 多谢各位
 
怎么解决的啊?
 
后退
顶部