求救,请帮我看一下,出了什么问题
我的程序运行可以,但是得不到我想要的结果。需要可以输入一段文字,然后数一下里面有多少个字符(character),还有多少个单词( words),有多少行(line),每个字符出现几次。
代码在下面:
import java.io.*;
import java.util.StringTokenizer;
public class InputTest
{
public static void main (String[] args)
throws IOException
{
BufferedReader console= new BufferedReader (
new InputStreamReader(System.in));
System.out.println ( " Enter your text, please( In Dos you type Ctrl+c, on UNIX you type Ctrl+D to finish your text): " + " \n" );
boolean done= false;
do
{
String inputLine = console.readLine();
if ( inputLine==null)
{
done = true;
System.out.println ( " Error, can not read the text.");
}
else
{
// count the number of words and characters
int characters=0;
StringTokenizer tokenizer= new StringTokenizer(inputLine);
int words= tokenizer.countTokens();
String[] data= new String[words];
for ( int i=0; i<data.length; i++)
{
data[i]= tokenizer.nextToken();
characters+= data[i].length();
}
// count the number of lines
int count=0;
String line= console.readLine();
do
{
count++;
line=console.readLine();
}
while ( line != null );
String output="\n" + " This text has " + count + " lines," + words + " words," + characters + " characters.";
System.out.println ( output );
// Count the occrrences of letters
String LowerCase= inputLine.toLowerCase();
LowerCase= LowerCase.trim ();
char letter[]= { "a","b","c","d","e",´f´,´g´,´h´,´i´,´j´,´k´,´l´,´m´,´n´,´o´,´p´,´q´,´r´,´s´,´t´,´u´,´v´,´w´,´x´,´y´,´z´};
String l_count="";
for ( int l=0; l<=25; l++)
{
int start = 0, n=0;
int end=LowerCase.length();
do {
char character= LowerCase.charAt(start);
if ( character== letter[l])
{
n++;
}
start++;
} while ( start< end);
System.out.println ( "Letter " + letter[l] + " : " + l_count );
}
}
} while ( !done);
}
}
谢谢各位大侠了!!!!