Java tutorial
//package com.java2s; public class Main { public static int cyclicIndex(int value, int size) { return ((value % (size = Math.abs(size))) + size) % size; } }