Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

ArrayList of prime numbers

import java.util.*;

public class test {
    public static void main(String[] args) {
        System.out.println(primeFinder(13));
    }

    public static ArrayList primeFinder(int n) {
        ArrayList<Integer> integerArray = new ArrayList<Integer>();
        
        for (int i = 1; i <= n; i++) {
            int count = 0;
            for (int j = i; j >= 1; j--) {
                if (i % j == 0) {
                    count++;
                }
            }
            if (count == 2) {
                integerArray.add(i);
            }
              
        }
        return integerArray;
    }
}
 
PREVIOUS NEXT
Tagged: #ArrayList #prime #numbers
ADD COMMENT
Topic
Name
7+1 =