Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andymccall/e28f2ae994a2925abc31f9d85d7584a8 to your computer and use it in GitHub Desktop.

Select an option

Save andymccall/e28f2ae994a2925abc31f9d85d7584a8 to your computer and use it in GitHub Desktop.

Revisions

  1. andymccall created this gist Mar 7, 2017.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original 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();
    }
    }

    }