Recherche dans un tableau à l’aide de la boucle ‘foreach’

Author:


{filelink=4409}

public class ForEachEtRecherche {
  public static void main(String args[]) {
    int nums[] = { 6, 8, 3, 7, 5, 6, 1, 4 };
    int val = 5;
    boolean found = false;

    for (int x : nums) {
      if (x == val) {
        found = true;
        break;
      }
    }

    if (found)
      System.out.println("Valeur trouvé!");
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *