标签:page 多少 pack out strong highlight art ack sys
totalCount总条数
pageCount每页总条数
totalPage总页数
先计算可以分为多少页-----------------
if(totalCount % pageCount == 0){
//整除,页面为整数
totalPage=totalCount/pageCount;
}else{
//有余数,页面加一
totalPage=totalCount/pageCount+1;
}
查询页面数据--------------------------
if(totalCount % pageCount == 0){
//整除的时候每页的初始数据
start=(n-1)*pageCount+1;
//整除的时候每页的最后数据
end=n*pageCount;
}else{
//有余数的时候查询页的初始数据
start=(n-1)*pageCount+1;
if(1<=n && n<totalPage){
//有余数的时候查询页的最终数据
end=n*pageCount;
}else{
//有余数的时候最后一页的最终数据
end=totalCount;
}
}
具体实现算法步骤:
package com.jiaguwen.zero;
import java.util.Scanner;
public class Pages {
public static void main(String[] args){
//totalCount总条数
//pageCount每页总条数
//totalPage总页数
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("请输入总条数:");
int totalCount = sc.nextInt();
System.out.println("请输入每页总条数:");
int pageCount = sc.nextInt();
int totalPage=0;
if(totalCount % pageCount == 0){
totalPage=totalCount/pageCount;
}else{
totalPage=totalCount/pageCount+1;
}
System.out.println("总页数为:"+totalPage);
while(true){
System.out.println("请输入查询的页数:");
int n = sc.nextInt();
int start=0,end=0;
if(n>totalPage||n<1){
System.out.println("没有此页!!!");
}else{
if(totalCount % pageCount == 0){
start=(n-1)*pageCount+1;
end=n*pageCount;
}else{
start=(n-1)*pageCount+1;
if(1<=n && n<totalPage){
end=n*pageCount;
}else{
end=totalCount;
}
}
System.out.println("查询第"+n+"的页面信息为:"+"起始条目"+start+",结束条目为"+end);
}
}
}
}
标签:page 多少 pack out strong highlight art ack sys
原文地址:https://www.cnblogs.com/YQian/p/11917317.html