public class Demo01 {
//用数组申明10个数,10个数的合输出
public static void main(String[] args) {
int[] sum = new int[10];//声明数组,创建数组
//给数组赋值
sum[0] = 1;
sum[1] = 2;
sum[2] = 3;
sum[3] = 4;
sum[4] = 5;
sum[5] = 6;
sum[6] = 7;
sum[7] = 8;
sum[8] = 9;
sum[9] = 10;
int s = 0;
for (int i = 0; i<=sum.length;i++){
s = s+i;
System.out.println(s);
}
//静态数组初始化
int[] i = {1,2,3,4,5,6};
System.out.println(i[5]);
//动态数组初始化
int[] s = new int[5];
s[0] = 1;
s[1] = 2;
s[3] = 4;
s[4] = 5;
System.out.println(s[2]);
}
}
原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/277356.html