ArrayList<String> accon = new ArrayList<String>();
ArrayList<Double> balance = new ArrayList<Double>();
try{
BufferedReader Buffer = new BufferedReader(new FileReader(new File(
"D://transactions.txt")));
String line = null;
while ((line = Buffer.readLine()) != null) {
// String arr[] = line.split(" ");
String Id = line.substring(0, 17);
String Case = line.substring(18, 19);
double a = Double.parseDouble(line.substring(20));
//System.out.print(""+Id+" "+Case+" "+a);
//System.out.println(" "+accon);
if (accon.isEmpty()) {
accon.add(Id);
//balance.add(0.0);
System.out.println("found A" + balance);
System.out.println("found Id " + Id);
if (Case.toUpperCase().trim().equals("D")) {
balance.add(a = a*-1);
System.out.println("Found Case " + Case);
System.out.println("Found balance" + balance);
} else if (Case.toUpperCase().trim().equals("C")) {
System.out.println("Found Case C = " + Case);
balance.add(a);
System.out.println("Found balance C =" + balance);
}
} else {
System.out.println("Hi");
int ii = 0;
System.out.println("not empty");
do {
System.out.println("welcome" + "II=" + ii);
if (accon.get(ii).equals(Id.trim())) {
System.out.println(accon + " = " + Id);
if (Case.toUpperCase().trim().equals("D")) {
System.out.println("Found Case D = " + Case);
System.out.println("balance.get(ii) = " + balance.get(ii));
balance.set(ii, balance.get(ii) - a);
System.out.println("II=" + ii);
System.out.println("balance.get(ii) = " + balance.get(ii));
System.out.println("the II =" + ii + " the balance D =" + balance);
} else if (Case.toUpperCase().trim().equals("C")) {
balance.set(ii, balance.get(ii) + a);
System.out.println("the II =" + ii + " the balance C =" + balance);
}
}
ii++;
} while (accon.size() >= ii);
System.out.println("----------------------------------------------");
}
}
for (int i = 0; i < accon.size(); i++) {
System.out.println(accon.get(i));
System.out.println(balance.get(i));
// System.out.println(accon.size());
}
}
catch(Exception e) {
System.out.print("" + e);
}
输出:
found A[]
found Id 00001500205568600
Found Case D
Found balance[-1520.15]
Hi
not empty
welcomeII=0
[00001500205568600] = 00001500205568600
Found Case D = D
balance.get(ii) = -1520.15
II=0
balance.get(ii) = -14020.15
the II =0 the balance D =[-14020.15]
welcomeII=1
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
答案 0 :(得分:0)
更改
cell_contents
到
>>> f2.__closure__[0].cell_contents is f3.__closure__[0].cell_contents
True
>>> f2.__closure__[0] is f3.__closure__[0]
True
的有效索引必须小于其大小(或者更准确,从while (accon.size()>=ii)
到while (accon.size()>ii)
)。