CS61B-debugexercise3中:
/**
* Created by jug on 1/22/18.
*/
public class DebugExercise3 {
//In会报错,需要新建一个类,代码在如下链接
public static int countTurnips(In in) {
int totalTurnips = 0;
while (!in.isEmpty()) {
String vendor = in.readString();
String foodType = in.readString();
double cost = in.readDouble();
int numAvailable = in.readInt();
if (foodType.equals("turnip")) {
int newTotal = totalTurnips + numAvailable;
totalTurnips = newTotal;
}
in.readLine();
}
return totalTurnips;
}
public static void main(String[] args) {
In in = new In("foods.csv");
System.out.println(countTurnips(in));
}
}
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/In.java.html