java 题这个怎么做,试题7的任务一,帮帮忙各位大神
1个回答
展开全部
试题7任务一
public class NumDemo {
public static void main(String[] args) {
int[] ary = new int[38];
for (int i = 0; i < ary.length; i++) {
ary[i]=i+1;
}
String qian="";
String hou="";
String yuandi="";
for (int i = 0; i < ary.length; i++) {
if(ary[i]%3==1){
qian+=ary[i]+",";
}else if(ary[i]%3==2){
hou+=ary[i]+",";
}else{
yuandi+=ary[i]+",";
}
}
System.out.println("向前一步的同学:"+qian);
System.out.println("向后一步的同学:"+hou);
System.out.println("原地不同的同学:"+yuandi);
}
}
输出
向前一步的同学:1,4,7,10,13,16,19,22,25,28,31,34,37,
向后一步的同学:2,5,8,11,14,17,20,23,26,29,32,35,38,
原地不同的同学:3,6,9,12,15,18,21,24,27,30,33,36,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询