java - How to get the 3rd element of an Arraylist as the sum of first two elements in an ArrayList in Android -


i pretty new programming world, kindly me in solving solution.

kindly consider suppose have x , y values. need add arraylist , z third element z's initial value 0 , next iteration onward z's value becomes sum of ((x[1] - x[0])+ (y[1]-y[0]))? how add values z , how sum of z?

try this,

you can add x values , y values in arraylist of integer or type , this,

int xsum, ysum, totalsum; arraylist<int> zsumlist;  zsumlist = new arraylist<int>;  zsumlist.add(0,0);  for(int = 1; < numberoftimes;i++) {     xsum = x[i] - x[i-1];     ysum = y[i] - y[i-1];      totalsum = xsum + ysum;      zsumlist.add(i,totalsum); } 

hope helps.


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -