Created
March 7, 2017 23:16
-
-
Save andymccall/e28f2ae994a2925abc31f9d85d7584a8 to your computer and use it in GitHub Desktop.
Revisions
-
andymccall created this gist
Mar 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ public class Main { public static void main(String[] args) { int numberOfPosts = 45; int pageSize = 3; int numberOfPages = numberOfPosts / pageSize; int lastPage = 0; int firstPage = 0; for (int i = 1; i < numberOfPages; i++) { if (i > lastPage) { lastPage = (lastPage + pageSize); firstPage = lastPage - pageSize + 1; if (lastPage > numberOfPages) { lastPage = numberOfPages; firstPage = lastPage - pageSize + 1; } } System.out.println("Current Page: " + i); System.out.println("First Page: " + firstPage); System.out.println("Last Page: " + lastPage); System.out.println(); } } }