I wrote an android app that solves quadratic equations and then is supposed to graph them. The library I am using requires the data sets to be in ArrayList form. However the loop I have to create the array involves adding a double to them which you cannot do with array lists. Here is the code:
List<double[]> x = new ArrayList<double[]>();
List<double[]> values = new ArrayList<double[]>();
QuadraticActivity c = new QuadraticActivity();
x=(c.xValueArr);
values=(c.yValueArr);
for (; c.xCurrent <= c.xEnd; c.xCurrent += c.xStep) {
double yCurrent = (c.a)*Math.pow(c.xCurrent, 2) + (c.b)*c.xCurrent + (c.c);
c. xValueArr .add ((c.xCurrent));
c. yValueArr .add ((yCurrent));
Judging from your code,
c.xValueArrandc.yValueArrare of type,double[]. If so, then just change the first 7 lines of code to this:Note: You’re instantiating two new ArrayLists in
lines 1 and 2but are replacing them inlines 6 and 7. Also, you’ll have to add the new values inside the loop manually, asxandvaluesdon’t point to the same arrays asc‘s arrays. A better fix would be to declare and initializexandvaluesafter the iteration, but since you didn’t include a closing}, I’m assuming you need them in the iteration.