【发布时间】:2019-07-11 13:48:56
【问题描述】:
导入 java.util.; 导入 java.io.;
公共类主要{ public static void main(String args[]){
int total = 0;
File file = new File("expenditure.txt");
Scanner fileScanner = new Scanner(file);
while (fileScanner.hasNextLine()) {
total += fileScanner.nextInt();
}
fileScanner.close();
System.out.println("The total expenditure is " + total);
}
}
【问题讨论】:
-
Java 教程:The
try-with-resourcesStatement