Ad
  • Custom User Avatar

    Almost. If itemCount could be zero, then that fails. Use

    return (itemCount + itemsPerPage - 1) % ItemsPerPage + 1;
    

    I don't remember if zero is allowed in the statement, but it should just be a habit in Java, C and C++ to avoid negative arguments to %.