菁英科技(卓目鸟学苑)- 专注软件测试菁英教育
标题:
java-魏清-20210308
[打印本页]
作者:
5269
时间:
2021-3-8 20:20
标题:
java-魏清-20210308
package
day02;
import
java.util.Arrays;
/*
数组
:
固定
长
度
相同
类
型
*/
public class
Demo05 {
public static void
main(String[] args) {
int
[] ids = {
1001
,
1002
,
1003
,
1004
};
System.
out
.println(ids[
0
]);
System.
out
.println(ids[
1
]);
System.
out
.println(ids[
2
]);
System.
out
.println(ids[
3
]);
// System.out.println(ids[4]); // ArrayIndexOutOfBoundsException
String[] names = {
"aaa"
,
"bbb"
,
"ccc"
,
"ddd"
};
System.
out
.println(names.
length
);
//
长
度
//
数组
的遍
历
,for
循
环
,使用索引遍
历
for
(
int
i =
0
; i < names.
length
; i++) {
System.
out
.println(
"hello,"
+ names
);
}
// foreach,
每次取
数组
中的一
个
元素
for
(String name : names) {
System.
out
.println(
"hello,"
+ name);
}
//
取
数组
中的最大
值
/
最小
值
int
[] nums = {
10
,
6
,
10
,
8
,
100
,
70
,
60
,
30
};
int
max = nums[
0
];
for
(
int
i =
1
; i < nums.
length
; i++) {
if
(nums
> max) {
max = nums
;
}
}
System.
out
.println(
"
最大值为:
"
+ max);
int
min = nums[
0
];
for
(
int
i =
1
; i < nums.
length
; i++) {
if
(nums
< min) {
min = nums
;
}
}
System.
out
.println(
"
最小值为:
"
+ max);
欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/)
Powered by Discuz! X3.4