java - Having for loop output sets of numbers? -


i have following code

    (int k=0; k<maxthreads; k++) {         int firstpart = k * tasksperthread;         int secondpart = ((k+1) * tasksperthread) - 1;         system.out.println(firstpart + "," + secondpart);     } 

where maxthreads inputted user , tasksperthread 10/maxthreads. maxthreads never less 1. outputs pairs of numbers. example, if maxthreads = 2 (making tasksperthread = 5) outputs

0,4 5,9 

covering ten values 0-9

i want ten values covered if maxthreads = 4. right code outputs this

0,1 2,3 4,5 6,7 

but cover 0-9. ideally output

0-2 3-5 6-7 8-9 

or combination has maxthreads number of sets of numbers , covers 0-9. how can adjust loop this?

thank you.

it being rounded down think, try using ceiling.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -