Given max number and range number, I want print out the following, but as short as possible. I don't know if this accomplish using IntStream.
input: max = 36 (or any number) range = 10 (or any number)
output: 0-9 10-19 20-29 30-35
my code:
totalItems=35
rangeMax=10
rangeFrom=0
rangeTo=0
while (true) {
if(totalItems>rangeTo+rangeMax){
rangeFrom=rangeTo+1;
rangeTo=rangeTo+rangeMax;
} else if(totalItems>rangeTo+1){
rangeFrom=rangeTo+1;
rangeTo=rangeTo+(totalItems-rangeFrom);
} else {
return null;
}
}