我是新來的Java和試圖找出如何將這個數據推入數組(6行,3列)?
x1 John 6
x2 Smith 9
x3 Alex 7
y1 Peter 8
y2 Frank 9
y3 Andy 4
然後,我會從最後一列進行數學計算。
這是我的代碼...
public class Testing {
public static void main(String[] args) {
Employee eh = new Employee_hour();
Employee_hour [] eh_list = new Employee_hour[6];
eh_list[0] = new Employee_hour("x1", "John", 6);
eh_list[1] = new Employee_hour("x2", "Smith", 9);
eh_list[2] = new Employee_hour("x3", "Alex", 7);
eh_list[3] = new Employee_hour("y1", "Peter", 8);
eh_list[4] = new Employee_hour("y2", "Frank", 9);
eh_list[5] = new Employee_hour("y3", "Andy", 4);
print(eh_list);
}
private static void print(Employee_hour[] mass){
for (int i = 0; i < mass.length; i++) {
System.out.print(mass[i] + " ");
}
System.out.println();
}
}
但我得到這個作爲輸出...
[email protected] [email protected] testing.Employee_hour @ 420a52f [email protected] [email protected] [email protected]
如何從最後一列獲得數字?
它需要是一個數組嗎?它不是最高效的數據結構 –
您是否必須使用數組或者是否可以使用其他數據結構?什麼是數據表示以及如何使用它?如果將數據放入Object [] []數組中,則以後使用該數據將會很麻煩。 – pgras
如果它不一定是一個數組,它可能值得使用地圖。 –