楼主,照你的说法,最后还剩两个数就没有规则来取出了,如果把最后剩的两个数依原序输出,顺序也应该是3,6,1,5,2,8,4,7。 import java.util.*;public class Test { public static void main(String[] arg) { int[] a = {1,2,3,4,5,6,7,8}; ArrayList<Integer> aa = new ArrayList<Integer>(); for(int i : a) { aa.add(i); } int index = 0; Set<Integer> indexSet = new HashSet<Integer>(); while(aa.size() > 0) { if(aa.size() == 1) { index = 0; } index = (index + 2) % aa.size(); System.out.print(aa.get(index) + ","); aa.remove(aa.get(index)); } } }
public static void main(String[] args) throws UnsupportedEncodingException
{
int[] a = {1,2,3,4,5,6,7,8,9,10,11};
boolean[] b=new boolean[a.length];
for(int i=0,j=0;;i++)
{
if(i>=a.length)
i=0;
if(!b[i])
{
j++;
if(j%3==0)
{
b[i]=true;
System.out.println(a[i]);
}
}
if(j==3*a.length)break;
}
}
import java.util.*;public class Test {
public static void main(String[] arg) {
int[] a = {1,2,3,4,5,6,7,8};
ArrayList<Integer> aa = new ArrayList<Integer>();
for(int i : a) {
aa.add(i);
}
int index = 0;
Set<Integer> indexSet = new HashSet<Integer>();
while(aa.size() > 0) {
if(aa.size() == 1) {
index = 0;
}
index = (index + 2) % aa.size();
System.out.print(aa.get(index) + ",");
aa.remove(aa.get(index));
}
}
}
请问四楼大虾,这句话是什么意思啊?加这一句编译时会出现没有符号的错误,不加这一句也可以运行出正确的结果。