May use Math.min(totalPage, currentPage + 1). Easier to read.