问题
填空题
本题定义了一个长度为10的boolean型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值为false,否则为true。
public class java1
public static void main(String[] args)
boolean b[]=______;
for(int i=0; i<10; i++)
if(______)
b[i]=false;
else
______;
for(int i=0; i<10; i++)
System. out. print("b["+i+"]="+b[i]+",");
答案
参考答案:第1处:new boolean[10]
第2处:i%2!=0
第3处:b[i]=true
解析: 第1处定义了一个长度为10的boolean型数组;第2处判断数组元素下标是否为奇数。第3处不为奇数的情况下数组元素值设为true。