我正在尝试从文本文件中删除0.0
的所有行。
这是它输出的内容:
0037823478362839 0.0
0236530128715607 3.88
0425603748320896 36.09
0659644925904600 13.58
0823485731970306 0.0
0836430488858603 46.959999999999994
这就是我想要输出的内容
0236530128715607 3.88
0425603748320896 36.09
0659644925904600 13.58
0836430488858603 46.959999999999994
代码:
// Collects the billing information and outputs them to a user defined .txt file
public void getBill() {
try {
PrintStream printStream = new PrintStream(outputFile);
Passenger[] p = getAllPassengers();
for(Passenger a : p){
printStream.print(a.getCardNumaber() + " ");
printStream.println(a.getBill());
}
printStream.close();
} catch(Exception e){
}
}
答案 0 :(得分:0)
要if
检查bill
金额是否为0.0
,如果不是,请打印,否则请勿打印。如果getBill()
返回一个String,那么你需要将该String解析为double,然后在if
中检查它。
for(Passenger a : p){
if(a.getBill() != 0.0){ // the if to check the value of bill
printStream.print(a.getCardNumaber() + " ");
printStream.println(a.getBill());
}
}
for(Passenger a : p){
double dBill = Double.parseDouble(a.getBill()); // in case getBill() returns a String
if(dBill != 0.0){ // the if to check the value of bill
printStream.print(a.getCardNumaber() + " ");
printStream.println(a.getBill());
}
}