Iterating an Array Using the for Statement [5.0] - Java Language Basics

Java examples for Language Basics:for

Description

Iterating an Array Using the for Statement [5.0]

for (type variable : array) {
    body-code
}

Demo Code

public class Main {
  // 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;//from   w  ww .  ja  va  2s . c om
      }
    }
    return min;
  }
}

Related Tutorials