本文主要是介绍java数组的声明基础,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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]);
}
}
这篇关于java数组的声明基础的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!