這個for循環應該對樹形圖中包含的所有值進行求和。這是有效的,但在內部循環之後,上下值用於計算精確度。看來這從來沒有被執行過。用Java簡單計算的問題
我在做什麼錯?
// for each row
for (Entry<String, TreeMap<String, Integer>> table_row : table.entrySet()) {
// write the label
String row = table_row.getKey() + ",";
int up = 0;
int down = 0;
float accu = 0;
// for each treemap in the row
for (Entry<String, Integer> collumn : table_row.getValue().entrySet()) {
row += collumn.getValue() + ",";
down += collumn.getValue();//this works
if (collumn.getKey() == table_row.getKey()) {
up = collumn.getValue();
}
}
---------> accu = (up/down) * 100; //this is not executed??
System.out.println("t: " + up + " n: " + down + " a: " + accu);
row = row + Float.toString(accu) + " %";
writer.println(row);//this works too but output is always 0%
}
你確定沒有例外嗎? – kosa 2012-07-31 20:31:47
沒有什麼是trowhn – jorrebor 2012-07-31 20:32:17
然後,我想聲明正在執行,但值可能是零 – kosa 2012-07-31 20:33:49