Mot Clé ‘break’: Chercher une éléments dans un tableau

Author:


{filelink=4314}

public class BreakDemo {
    public static void main(String[] args) {

        int[] arrayDeInts = { 32, 87, 3, 589, 12, 1076,
                              2000, 8, 622, 127 };
        int rechercheVal = 12;

        int i = 0;
        boolean trouvé = false;

        for ( ; i < arrayDeInts.length; i++) {
            if (arrayDeInts[i] == rechercheVal) {
                trouvé = true;
                break;
      }
        }

        if (trouvé) {
      System.out.println("foundIt " + rechercheVal + " à l'index " + i);
        } else {
      System.out.println(rechercheVal + "non trouvé dans le tableau");
        }
    }
}

A Voir sur le même Sujet:

  • le mot cle break dans python

Leave a Reply

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