我有这个代码来计算输入字符串中 * 的数量。但我需要从文本文件中找到它。任何的想法?
import java.lang.String;
import java.io.*;
import java.util.*;
public class CountStars {
public static void main(String args[]) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the String:");
String text = bf.readLine();
int count = 0;
for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c=='*' ) {
count++;
}
}
System.out.println("The number of stars in the given sentence are " + count);
}
}