In class, we perform the following program, used to calculate the first n prime numbers of some amount that the user enters by keyboard, but I have not understood the teacher well, I am new to this, thank you very much.
Scanner sc = new Scanner (System.in);
int li, suma=0;
int cont = 0;
System.out.println("Ingrese la longitud de los numeros primos a sumar");
li= sc.nextInt();
for(int i = 2; i <= li; i++)
{
cont = 0;
for (int j = 1; j <= i; j++)
{
if(i % j == 0)
{
if(j == i)
cont++;
}
}
if(cont== 2 )
{
suma= suma + i;
}
}
System.out.print(suma + " ");