Este programa muestra un error de tiempo de compilación ... inicio ilegal de tipo para (Integer it: arr), ¿por qué muestra un error? [duplicar]
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");
}}
Respuestas
Verity Dec 19 2020 at 16:27
Coloque su bucle for dentro del método principal, así:
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);
}
}