Ce programme affiche une erreur de compilation .. Début illégal de type pour (Integer it: arr), pourquoi il affiche une erreur? [dupliquer]
Dec 19 2020
import java.util.*;
class Test
{
Set<Integer> st = new HashSet<Integer>();
Integer arr[]={1,1,2,2,4,8};
for (Integer it : arr)
{
st.add(it);
System.out.println(st);
}
public static void main(String ar[]){
System.out.println("Main");
}}
Réponses
Verity Dec 19 2020 at 16:27
Mettez votre boucle for dans la méthode principale, comme ceci:
public static void main(String ar[]) {
Set<Integer> st = new HashSet<Integer>();
Integer arr[]={1,1,2,2,4,8};
for (Integer it : arr) {
st.add(it);
System.out.println(st);
}
}