开发者

How to get elements from a double[] Array

How do I list the elements from a double[] Array. Here is my init and assignment.

final int nr=10;

double[] cArray= new double[100];
System.arraycopy(Global.ArrayAlpha, 0, cArray, Global.ArrayBeta.length, Global.ArrayAlpha.length);

for(int i=0;i< nr;i++){
    System.println( cArray?????);
}

A simiple question, I know , but all attempts have开发者_高级运维 been unsuccessful. The program is java and I get the following error when i use cArray.get(k)

Cannot invoke get(int) on the array type


for (double x : cArray) System.out.println("" + x);

OR

for (int i = 0; i < cArray.length; i++) System.out.println("" + cArray[i]);


You have to use array element access [], i.e.

 System.out.println(cArray[i]);

An alternative way is foreach loop:

 for(double currentDouble : cArray) { /* use currentDouble here */ }

Also note, that println is a function of System.out (the standard output) rather than System


Arrays are not objects. If you want to get a specified element from an array use the following syntax: myArray[123] to get 123th element from 0-based index.


for (double d : cArray) {
  System.out.println(d);
}

or

for (int i = 0; i < cArray.length; i++) {
   System.out.println(cArray[i]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜