首页 > 编程语言 > 详细

e1087. 用For循环做数组的遍历

时间:2018-09-02 21:20:33      阅读:244      评论:0      收藏:0      [点我收藏+]

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

e1087. 用For循环做数组的遍历

原文:https://www.cnblogs.com/borter/p/9575283.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!