Search
 
SCRIPT & CODE EXAMPLE
 

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;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: overload and override in java 
Java :: startactivity not working in android adapter 
Java :: difference between stringbuffer and stringbuilder 
Java :: add infinite values to variable java 
Java :: java Math.sqrt(double) 
Java :: keep jframe on top 
Java :: type variable java 
Java :: java convert double to boolean 
Java :: windows Jmeter java.net.BindException: Address already in use: connect 
Java :: how to create Java ArrayList 
Java :: int[] java 
Java :: convert jwt claim to string java 
Java :: object type in java 
Java :: how to know if a file is iso-8859-1 encoded in java 
Java :: hwo to create a list of 1 to n nums in java list 
Java :: difference between getcontext and getapplicationcontext in android 
Java :: JFrame change outline 
Java :: what is a cache-less reload 
Java :: convert stringbuffer to string in java 
Java :: boolean checkbox swing 
Java :: array copy java 
Java :: change fab image programatically 
Java :: webview dark mode android 
Java :: fibonacci of 6 
Java :: 1 elemenet array java 
Java :: long java 
Java :: java record 
Java :: java and or precedence 
Java :: capture console output java 
Java :: java collectors mapping 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =