1
I have to create an algorithm in java to detect the prime numbers in a range that the user choose for example "the existing numbers from 1 to 50" the result is coming out correct in the eclipse console but it keeps repeating several times the answer (1,1,1,1,1,1,3,3,3,3,3,3,3,5,5,5,5,5) e assim por diante.
import java.util.Scanner;
public class EXC29 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println("Entre com um numero ");
int num = scan.nextInt();
for(int i = 1;i<=num;i++) {
boolean primo = true;
for(int j = 2;j<i;j++) {
if(i%j == 0) {
primo = false;
}
if(primo) {
System.out.println(i);
}
}
}
}
}