Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static boolean isPrime(int n) {
- //check if n is a multiple of 2
- if (n%2==0) return false;
- //if not, then just check the odds
- for(int i=3;i*i<=n;i+=2) {
- if(n%i==0)
- return false;
- }
- return true;
- }
- public static void main(String[] args){
- int sum = 0;
- for (int i = 0; i < args.length; i++) {
- int number = Integer.parseInt(args[i]);
- if (isPrime(number))
- System.out.println(number);
- sum = sum + number;
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement