java - Android: 100 - Random number instead the 100 became random -
im trying subtract 100 , random number instead 100 became random number itself.
below block of code used generate random number , subtract life
100
.
public void run() { random r1 = new random(); int n1 = r1.nextint(10 - 1) + 1; int life1 = 100; damage1.settext(string.valueof(n1)); for(;life1 > 0; life1 -= n1) { bar1.setprogress(life1); percent1.settext(string.valueof(life1) + "%"); } }
in code life1 = life1 - n1;
value returned being reinitialized. must use forloop
or loop increment/decrement operator variable.
Comments
Post a Comment