Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
githublock
java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
java
/
javase
/
code
/
2019-08-17
/
ArrayDemo.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
68 lines (59 loc) · 1.44 KB
master
Breadcrumbs
java
/
javase
/
code
/
2019-08-17
/
ArrayDemo.java
Copy path
Top
File metadata and controls
Code
Blame
68 lines (59 loc) · 1.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
数组表示存储相同数据类型数据的有序集合
特点:
1、数组中存放的数据必须是同一个数据类型,可以是基本数据类型也可以是引用数据类型
2、数组在定义的时候必须要给定大小,且大小不可以改变
3、可以通过下标值来获取数据,下标从0开始
4、插入数组中的数据是有序集合,此时有序并不是指代大小排序,而是指插入的顺序
使用:
1、声明数组
2、创建空间
3、赋值
4、数组操作
*/
public
class
ArrayDemo
{
public
static
void
main
(
String
[]
args
){
/*
//声明数组
int[] array;
//创建内存空间
array = new int[5];
//数组赋值
array[0] = 0;
array[1] = 1;
array[2] = 2;
array[3] = 3;
array[4] = 4;
//数组操作
System.out.println(array[0]);
//数组的几种创建方式
//1、声明并申请空间
int[] arr1 = new int[5];
int [] arr2 = new int[5];
int arr3[] = new int[5];
//2、声明数组并赋值
int[] arr4 = new int[]{1,2,3,4,5};
//3、直接初始化操作
int[] arr5 = {1,2,3};
//获取数组的长度
System.out.println(arr1.length);
//输入5个数值,求平均值
int[] arr6 = new int[]{56,98,34,89,100};
int sum = 0;
for(int i = 0;i<arr6.length;i++){
sum+=arr6[i];
}
System.out.println("平均值是:"+sum/arr6.length);
*/
/*
数组是引用类型,当创建完成数组之后相当于是在方法外定义了一个变量,此时数组中的值是有默认值的
默认是什么,取决于你定义的数组的类型:
int:0
String null
boolean false
数组可以根据下标获取值,但是获取的时候下标的范围是[0,length-1]
*/
int
[]
array
=
new
int
[
5
];
System
.
out
.
println
(
array
[
0
]);
}
}
You can’t perform that action at this time.