Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created January 22, 2019 09:21
Show Gist options
  • Save bastienapp/8de679b22f96d789d2b62aa94fb34750 to your computer and use it in GitHub Desktop.
Save bastienapp/8de679b22f96d789d2b62aa94fb34750 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int[] vector = null;
Integer result = null;
try (Scanner scanner = new Scanner(new File(args[0]))) {
String[] numberTokens = scanner.nextLine().split(",");
vector = new int[numberTokens.length];
for (int i = 0; i < numberTokens.length; i++) {
vector[i] = Integer.parseInt(numberTokens[i]);
}
}
catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
/* YOUR CODE HERE */
for (int i = 1; i < vector.length; i+=2) {
int num = vector[i];
// TODO : tester si value est premier ?
boolean notPrime = false;
for (int j = 2; j <= num/2; ++j) {
// condition for nonprime number
if(num % j == 0) {
notPrime = true;
break;
}
}
if (!notPrime && (result == null || num < result)) {
result = num;
}
}
if (result != null) {
System.out.println(result);
} else {
System.out.println("NULL");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment