ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java数组的声明基础

2022-07-27 18:34:45  阅读:36  来源: 互联网

标签:10 java int sum System 数组 println 声明


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]);



}
}

标签:10,java,int,sum,System,数组,println,声明
来源: https://www.cnblogs.com/yujianxuexi/p/16525877.html

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有