1

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

2
  • What kinda errors are u getting? is Global.ArrayAlpha the same length as cArray (100) ? Commented Sep 11, 2011 at 13:20
  • 1
    And the programming language is...? Commented Sep 11, 2011 at 13:20

4 Answers 4

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

OR

for (int i = 0; i < cArray.length; i++) System.out.println("" + cArray[i]);
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

1 Comment

Actually arrays ARE objects and myArray[123] will give you the 124th element (including element 0).
0
for (double d : cArray) {
  System.out.println(d);
}

or

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.