Este programa está mostrando erro de tempo de compilação .. início ilegal do tipo para (inteiro it: arr), por que está mostrando erro? [duplicado]

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");


}}

Respostas

Verity Dec 19 2020 at 16:27

Coloque seu loop for dentro do método principal, assim:

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);
    }


}