我在一个从0到5的循环中有一组索引。如果用户指定的索引大于5,例如7,则应该返回索引7-6=1。如果指定的索引小于0,ex -2,则应返回索引-2+6=4。在第一种情况下,我们可以使用余数运算符来处理大于5的值: int inputValue = 7;
int result = inputValue%6; 但是,是否有类似的操作可以很好地处理指定索引低于0
如果我有6的索引位置,我只想得到第一句话:Dana's places, we're having people coming to us people wanna buy condos.如果我有80的索引位置,我只想得到第二句话:They want to move quickly and we're just losing out on a lot of great places.