java - Automate Logic using Loops? -


i need automate below code snippet using loops. need max values if availpoints reaches infinite numbers

how can achieve within few lines of codes

if (availpoints < 500 ) {    pointsmax = 500;    moneymax = 25; } else if (availpoints < 1000 ) {    pointsmax = 1000;    moneymax = 50; } else if (availpoints < 1500 ) {    pointsmax = 1500;    moneymax = 75; } 

update:

assume availpoint points user score 1 1000000(infinite too). every 500 points slot. if points enter next slot. max values pointmax has incremented 500 & moneymax 25.

it not require loop.

    (int availpoints = 400; availpoints < 2000; availpoints += 200) {         int rank = availpoints / 500;         int pointsmax = (rank + 1) * 500;         int moneymax = (rank + 1) * 25;         system.out.printf("availpoints %d -> pointmax=%d moneymax=%d%n",             availpoints, pointsmax, moneymax);     } 

result:

availpoints 400 -> pointmax=500 moneymax=25 availpoints 600 -> pointmax=1000 moneymax=50 availpoints 800 -> pointmax=1000 moneymax=50 availpoints 1000 -> pointmax=1500 moneymax=75 availpoints 1200 -> pointmax=1500 moneymax=75 availpoints 1400 -> pointmax=1500 moneymax=75 availpoints 1600 -> pointmax=2000 moneymax=100 availpoints 1800 -> pointmax=2000 moneymax=100 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -