• Post Reply Bookmark Topic Watch Topic
  • New Topic

what does this += or -=  RSS feed

 
ekte spiriopoulos
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have this method .Can some one explain me += what it does there?
public static int getSKos(Vehicle[] pin) {

int ks = 0;

for(int i =0; i < pin.length; i++) {
ks += pin[i].getKsOxis();
}

return ks;
}
 
yousaf khan
Greenhorn
Posts: 24
1
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose we have two variables "a" and "b" and we want to add "b" in to "a". If we write "a+=b", this is just another way of adding "b" in to "a" and is same as "a=a+b".
Similarly in your code, at line "ks += pin[i].getKsOxis(); ", its just another way of adding value of pin[i].getKsOxis() in to ks and is same as "ks=ks+pin[i].getKsOxis();".
 
John Pacuta
Greenhorn
Posts: 26
1
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ekte!

You have this public method "getSKos(Vehicle[] pin)" that accepts a Vehicle array called "pin". For every element of pin, the another method "getKSOxis()" is called and an integer is returned and added to "ks". About the "+=" that is just a way to add a value to itself, in other words 1 += 2 is the same as 1 = 1 + 2. I hope that helps!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!