1
I created a program to check primes and in it I receive n
entries. That is to say, n
is the number of test cases. The problem is that in the first test case everything works fine. Already in the second the program is wrong to say if 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?
Thank you very much, bigown!
– Kfcaio