2012-06-18 78 views
0

我有一個包含12個數字的數組,我想將這12個數字保存在12個浮點數中。通常我應該如何執行此操作並將它們中的每一個保存在一個浮點數中?單獨的數組數並將它們保存爲浮點數

array numbers = { a,b,c,....} 
object1 = a; 
object2 = b; 
+0

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html –

+0

告訴我們哪些類型數Ur數組包含的? –

回答

2
int[] numbers = { 1, 2, 3, 4, 5, ... }; 
float f1 = (float) numbers[0]; 
float f2 = (float) numbers[1]; 
... 
1
int[] numbers = { 1, 2, 3, 4, 5, 6 }; 

float[] num_floats = new float[numbers.length]; 

for (int i = 0; i < numbers.length; i++) 
{ 
    num_floats[i] = (float) numbers[i]; 
} 
相關問題