懵懂的菜鸟

Stay hungry,Stay foolish.

导航

搜狐畅游编程题

 1 package Campus;
 2 import java.util.Scanner;
 3 public class Main {
 4     public static void main(String[] args) {
 5         int num=0;
 6         int p=0;
 7         int p_max=0;
 8         int count=0;
 9         Scanner s=new Scanner(System.in);
10         while(s.hasNext()){//用于循环输入,对结果无影响
11             num=s.nextInt();
12             int[] arr=new int[num];
13             for (int i = 0; i < num; i++) {
14                 arr[i]=s.nextInt();
15             }
16             p=s.nextInt();
17             p_max=s.nextInt();
18             //先判断,当页数超过总页数时
19             if(p>num/p_max){
20                 System.out.println("超出分页范围");
21             }
22             //如符合条件,进行输出
23             else{
24                 for(int j=p*p_max;j<(p+1)*p_max&&j<num;j++){
25                     System.out.println(arr[j]);
26                 }
27             }
28             
29         }
30         
31     }
32 
33 }

 

posted on 2017-09-17 14:55  懵懂的菜鸟  阅读(193)  评论(0编辑  收藏  举报