This site requires JavaScript, please enable it in your browser!
Greenfoot back
Back to discussions
MakerOfGames
MakerOfGames wrote ...

2012/9/9

How fast do the numbers add in x=x+1

MakerOfGames MakerOfGames

2012/9/9

How much numbers per second is added to x when its x=x+1?
erdelf erdelf

2012/9/9

well, when do you call this?
Gevater_Tod4711 Gevater_Tod4711

2012/9/9

Do you mean how long it will take because you need the value in the next line like this:
int x = 0;
x = x + 1;
turn(x);
then the answer is simple: Java will not execute the next line while the line before is not processed. If you mean how much runtime it will take: It's just a addition and it'll not take much runtime. But better use this:
int x = 0;
x += number;
//or if the number is 1 you better do this;
x++;
in this cases Java only needs to call the value x one time, not two times like in your case
You need to login to post a reply