temp java

随意输入,2个数。比如 5,3 。就有一个数组长度等于5。然后开始数数,每次数到3时,打印出数到的数的值,数组中的元素只会被打印一次。最后只剩一个元素的值的时候,以 【last : 元素值】 的格式打印出来

例:输入 5,3 打印出

3
1
5
2
last : 4

 

 public static void pInt(int[] in,int s){
        if(in.length == 1){
            System.out.println("last : " + in[0]);
            return;
        }
        int stemp = s;
        if(in.length < s){
           s = in.length % s -1; 
          // System.out.println("s " + s);
        }
        int tempLength = in.length - 1;
        int [] tempIn = new int[tempLength];
        int tempc = 0;
        for(int i = 0 ; i < in.length ; i++){
            if(i == s-1){
                System.out.println(in[i]);
            } else {
                if(i > s-1){
                    tempIn[tempc] = in[i];
                    tempc++;
                }else{
                 tempIn[in.length - s + i  ] = in[i];
                }
            }
        }
//        System.out.println("tempIn.length " + tempIn.length);
//        for (int i = 0; i < tempIn.length; i++) {
//            System.out.println("a : " + tempIn[i]);
//        }
        pInt(tempIn,stemp);
    }
    
    public static void main(String[] args) {
        pInt(new int[]{1,2,3,4,5} , 3);
        System.out.println("----------------------------------");
        pInt(new int[]{1,2,3} , 5);
    }
 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值