Java: Parcourir un tableau avec la boucle foreach

Author:


{filelink=4407}


public class ClassPrincipale{
  public static void main(String args[]) {
    int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    # Affucher le contenu du tableau
    for (int x : nums) {
      System.out.print(x + " ");
      x = x * 5; // aucun effet sur la table nums
    }

    System.out.println();

    for (int x : nums)
      System.out.print(x + " ");

    System.out.println();
  }
}

Leave a Reply

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