How can I make a for-loop with array of doubles?

Gabriel Dias :

I'm trying to make a for-loop with an array of doubles, but it just doesn't work.

Here is the code:

double[] myDoubleArray = new double[10];
double piValue = 3.141592;

for (double i = 0; i < 10; piValue+) {
    myDoubleArray[i] += i;
}

System.out.println(myDoubleArray[2]);
System.out.println(myDoubleArray[5]);
Jahangir :

Actually for array indexing use int. You can follow below code

    double[] myDoubleArray = new  double[10]; 
    double piValue = 3.141592; 
    for (int i = 0; i < 10; i++) { 
          myDoubleArray[i] = piValue + i; 
    }
 System.out.println(myDoubleArray[2]);

 System.out.println(myDoubleArray[5]);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=31879&siteId=1