Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created January 22, 2019 10:12
Show Gist options
  • Save bastienapp/947b78ebddf729f775b3f2216aef0b8c to your computer and use it in GitHub Desktop.
Save bastienapp/947b78ebddf729f775b3f2216aef0b8c to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.*;
class Main {
public static void main(String[] args) {
int N;
int[] result = null;
List<Integer> resultList = new ArrayList<>();
try (Scanner scanner = new Scanner(new File(args[0]))) {
N = Integer.parseInt(scanner.nextLine());
/* YOUR CODE HERE */
for (int num = 2; num < N; num++) {
// TODO : tester si i est premier
boolean notPrime = false;
for (int i = 2; i <= num/2; ++i) {
// condition for nonprime number
if (num % i == 0) {
notPrime = true;
break;
}
}
if (!notPrime) {
resultList.add(num);
}
}
for (int j = 0; j < resultList.size(); j++) {
System.out.print(resultList.get(j));
if (j < resultList.size() - 1) {
System.out.print(" ");
}
}
System.out.println();
}
catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment