java - How to add a value to a specific row in a 2d array -
i trying number user input row number of 2d array existed , number value needs added elements of row. have no idea how it. please me , give me idea start.
so example if have 2d array , content is:
2 3 4 5 1
2 6 2 5 6
4 2 6 2 1
i know how numbers user input , locate row don't know how add second number elements of row.
for example:
- if user inputs 0 row number.
- we got 2 3 4 5 1 located.
- then user inputs 2 value of addition.
i need 2+2 3+2 4+2 5+2 1+2 , save row 0 2d array. how can it?
if you're stuck on 2d array syntax, it's this:
myarray[0][0] = myarray[0][0] + 2; myarray[0][1] = myarray[0][1] + 2; myarray[0][2] = myarray[0][2] + 2; myarray[0][3] = myarray[0][3] + 2; myarray[0][4] = myarray[0][4] + 2;
or more concisely:
for (int i=0, length=myarray[0].length; i<length; i++) { myarray[0][i] += 2; }
Comments
Post a Comment