A-A+
本题定义了一个长度为l0的boolean型数组 并给数组元素赋值 要求如果数组元素下标为奇数
问题详情
本题定义了一个长度为l0的boolean型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值 为false,否则为true。 public class javal{ pubhc 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("bE"+i+"]="+b[i]+","); } }请帮忙给出正确答案和分析,谢谢!
参考答案
正确答案:
第1处:new boolean[10]
第2处:i%2 1=0
第3处:b[i]=true
【解析】第1处定义了一个长度为10的boolean型数组;第2处判断数组元素下标是否为奇数。第3处不为奇数的情况下数组元素值设为true。