Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- public class t3{
- public static void main(String[] args){
- long num = 100;
- //declaring list and filling it with numbers
- ArrayList<Long> numlist = new ArrayList<Long>();
- for(long x=2 ; x<num ; x++){
- numlist.add(new Long(x));
- }
- //sieve or eratosthenes
- for(long x=0 ; x<Math.sqrt(num) ; x++){
- for(long y=x+1 ; y<numlist.size() ; y++){
- if(numlist[y]%numlist[x] == 0){
- numlist.remove(y);
- }
- }
- }
- //print list
- for(Object item : numlist){
- System.out.println((Long)item);
- }
- }
- }
Add Comment
Please, Sign In to add comment