I have created a prime number verification program and receive n
entries in it. That is, n
is the number of test cases. The problem is that in the first test case everything works fine. Already in the second onwards the program errs in saying whether the number is prime or not.
import java.util.Scanner;
public class Main {
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int contador = 0;
for(int i = 1; i <= n; i++){
int v = sc.nextInt();
for(int j = 1; j <= v; j++){
if(v % j == 0){
contador++;
}
}
if(contador == 2){
System.out.println("PRIME");
}
else{
System.out.println("NOT PRIME");
}
}
}
}
How to fix?