【发布时间】:2015-11-18 06:42:20
【问题描述】:
这是我目前的方法。我试图在一个名为 in.txt 的文件中计算一个 A 字母。
public void countFile() {
BufferedReader reader;
int counter=0;
try {
reader = new BufferedReader(new FileReader("in.txt"));
}
catch(IOException ioException) {
System.err.println("Error Opening File: Terminating");
System.exit(1);
}
int data = reader.read();
while(data != -1) {
char charToSearch = 'A';
//this is the part i mess up and i dont know how to fix it the char data have to be int and the char to search is char.
if(charToSearch = (char) data); {
counter++;
}
};
reader.close();
System.out.println(counter);
}
感谢大家帮助我。我一直在努力,但我无法解决它。
【问题讨论】:
-
(1) 比较两个值是否相等的 Java 运算符是什么? (2)
if语句的正确语法是什么? -
=和==和while() {...};之间有区别是错误的 -
(3) 你有一个循环,直到
data是-1。但是,data在您的循环中的哪个位置发生了变化? -
谢谢大家。你们是我所拥有的最好的社区。span>