我需要计算文件中所有以字母“A”开头和结尾的单词。虽然我能够计算文件中的所有单词。这是代码...
public class task_1 {
public static int i;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner (System.in);
String name = sc.nextLine();
sc.close();
FileReader fr2 = new FileReader(name);
BufferedReader r = new BufferedReader(fr2);
String s=r.readLine();
int n=0;
while(s!=null) {
System.out.println(s);
String [] words = s.split(" ");
n += words.length;
for(String str : words)
{
if(str.length()==0) n--;
}
s=r.readLine();
}
fr2.close();
System.out.println(n);
}
}