e1087. 用For循环做数组的遍历
2024-09-02 04:25:39
The for
statement can be used to conveninently iterate over the elements of an array. The general syntax of the array-based for
statement is:
for (type variable : array) {
body-code
}
The array-based for
statement has four parts. The array is an expression that returns an array. The type specifies the type of variable which will be used to hold elements from the array. In particular, variable always holds the current element of the iteration and can be used by the code in body-code. body-code is code that will be executed once for every element in the array. Here is an example of the for
statement.
// Returns the smallest integer in the supplied array
public int getMin(int[] ints) {
int min = Integer.MAX_VALUE;
for (int num : ints) {
if (num < min) {
min = num;
}
}
return min;
}
Related Examples |
最新文章
- Android 蓝牙API详解
- Java关键字final、static使用总结
- jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()的区别
- HDU5898、 HDU 2089(数位DP)
- 使用struts2的<;s>;标签出错
- HW7.17
- python学习--string
- C语言学习笔记--结构体
- unix c 10
- PV IP UV
- Ubuntu系统下配置IP地址方法介绍
- 2018最新iOS端界面UI设计规范整理
- 给定数组长度2n,分成n对,求n对最小元素之和最大
- Django项目的创建
- 关于setvbuf()函数的详解
- TensorFlow安装之后导入报错:libcudnn.so.6:cannot open sharedobject file: No such file or directory
- CF1110E Magic Stones(构造题)
- go语言之进阶篇数组越界导致panic
- Android -- 触摸Area对焦区域(更新)
- canvas线性变换、颜色和样式选择