2017年计算机二级《JAVA》模拟基本操作试题
来源:学生作业帮助网 编辑:作业帮 时间:2024/04/25 08:28:59 计算机等级考试
2017年计算机二级《JAVA》模拟基本操作试题计算机等级考试
二、基本操作题
本题中定义了一个长度为20的整数数组,然后将1~20分别赋给数组元素,计算该数组中所有下标为奇数的元素的和。
public class javal{
public static void main(String args[]){
int sum;
;
int arrayList[]=new int[20];
for(int i=0;i<=19;i++)
arrayList[i]=i+1;
int pos=0;
while(pos<20){
if( )
sum=sum+arrayList[pos];
;
}
System.out.println("sum="+sum);
}