首页 > 其他分享 >给定一个list和一个int数值,循环打印固定范围内list的元素

给定一个list和一个int数值,循环打印固定范围内list的元素

时间:2023-04-07 16:11:58浏览次数:46  
标签:count strength indexList int list 给定 size

比如有一个list,里面有“1, 2, 3, 4, 5, 6, 7, 8”这八个元素,再给一个int数值,比如是3,那打印结果就是

第一次:1, 2, 3

第二次:4, 5, 6

第三次:7, 8, 1

第四次:2, 3, 4

依次类推...

public static void main(String[] args) {
    int strength = 3;
    List<Integer> indexList = new ArrayList<>();
    List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
    int size = list.size();
    int count = 0;
    for (int i = 0; i < 32; i++) {
        for (int j = 0; j < strength; j++) {
            int index = (count + j) % size;
            indexList.add(index);
        }
        for (int m = 0; m < indexList.size(); m++) {
            Integer integer = indexList.get(m);
            System.out.println(list.get(integer));
        }
        System.out.println("---------------------");
        count+=strength;
        indexList.clear();
    }
}

 

标签:count,strength,indexList,int,list,给定,size
From: https://www.cnblogs.com/shamo89/p/17296500.html

相关文章

  • StringToByte(char* source, uint8_t* dest, int sourceLen)
    voidStringToByte(char*source,uint8_t*dest,intsourceLen){inti;uint8_thighByte,lowByte;for(i=0;i<sourceLen;i+=2){highByte=toupper(source[i]);lowByte=toupper(source[i+1]);if(highB......
  • JUC并发编程基础篇第五章之线程中断状态[你理解的线程中断,只会Thread.interrupted()
    目录1、什么是线程的中断机制2、isterruptinterruptedisInterrupted区别3、面试题3.1、如何停止中断运行中的线程3.2、当前线程的中断标识符为true,是不是线程就立马停止了3.3、如果线程处于被阻塞的状态(列入sleep,wait,join等状态),在别的线程调用当前线程的interrupt()方法,会发生......
  • [paper reading]|IC-FPS: Instance-Centroid Faster Point Sampling Module for 3D Po
    摘要:本文说首次实现了大规模点云场景中基于点的模型的实时检测(<30ms);首先指出FPS采样策略进行下采样是耗时的,尤其当点云增加的时候,计算量和推理时间快速增加;本文提出IC-FPS;包含两个模块:localfeaturediffusionbasedbackgroundpointfilter(LFDBF);CentroidInstanceSampl......
  • 【中文乱码】HttpServletResponse PrintWriter中文乱码解决方法
    HttpServletResponse使用PrintWriter输出中文的时候,如果不设置流的编码就会产生乱码,PrintWriter直接输出的字符流首先使用"response.setCharacterEncoding(charset)"设置字符以什么样的编码输出到浏览器,如果不设置则默认是ISO-8859-1,这个是不支持中文的。解决方法publicvoid......
  • PrintDocument DrawString C# 换行问题
    在使用80mm小票机做再次开发时使用DrawString无法自动换行导致文字被截断终于找到解决方案:别忘了给我点赞,留言源代码如下:立跑可用 链接:https://pan.baidu.com/s/1vywMUvGXMaFh_1o7ywDQTA?pwd=yyyy提取码:yyyy......
  • A C++ program that prints itself
    #include<iostream>usingnamespacestd;intmain(){strings="cout<<\"#include<iostream>\\nusingnamespacestd;\\n\\nintmain(){\\nstrings=\\\"\";\nfor(chari:s)\nif(i==�......
  • freemarker处理list的内置函数
    freemarker处理list的内置函数first没有括号last没有括号seq_containsseq_index_ofsize没有括号reversesortsort_by如果list中放置的是对象的话,可以根据某个属性来排序chunk将list分块<#assignlistVar=[1,2,3,4,5,6,7,8,9,0,1,2]/><#listlistVa......
  • 带删除按钮的ListView
    不用说了,上图先:importjava.util.ArrayList;importcom.ql.adapter.DeletableAdapter;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;impo......
  • Lazy延时加载的ListView
    使用的是第三方开发包CWAC-AdapterWrapper.jarpackagecom.ql.app;/***Copyright(c)2008-2009CommonsWare,LLCLicensedundertheApacheLicense,Version2.0(the"License");youmaynotusethisfileexceptincompliancewiththeLi......
  • org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationExcept
    错误信息:com.xubo.rabbitmq.springbootrabbitmq.SpringbootRabbitmqApplication._________/\\/___'_____(_)______\\\\(()\___|'_|'_||'_\/_`|\\\\\\/___)||_)||||......