分页导航算法

来源:互联网 发布:课程优化 编辑:程序博客网 时间:2024/06/06 05:53

这里写图片描述

package test;import java.util.ArrayList;import java.util.List;public class Z {    public static void main(String[] args) {        int currentPage = 15;        int pageCount = 100;        List pageList = new ArrayList();        int floatPositionCount = 5;        if (currentPage - 5 - 1 == 2 || currentPage - 5 - 1 == 1                || currentPage - 5 - 1 <= 0) {            for (int i = 0; i < currentPage; i++) {                pageList.add(i + 1);            }        } else {            pageList.add(1);            pageList.add("...");            int beginNum = currentPage - 5 - 1;            for (int i = beginNum; i < currentPage; i++) {                pageList.add(i + 1);            }        }        if (currentPage + 5 == pageCount - 2                || currentPage + 5 == pageCount - 1                || currentPage + 5 >= pageCount) {            for (int i = currentPage; i < pageCount; i++) {                pageList.add(i + 1);            }            System.out.println("this");        } else {            int beginNum = currentPage;            for (int i = beginNum; i < beginNum + 5; i++) {                pageList.add(i + 1);            }            pageList.add("...");            pageList.add(pageCount);        }        for (int i = 0; i < pageList.size(); i++) {            System.out.print(pageList.get(i) + " ");        }    }}
0 0
原创粉丝点击