storage - Using ArrayDeque Java -


i'm trying store list of primes using java , came across arraydeque. i'm not sure if correct occasion use it, since don't know number of primes need capacity grow.

the code designed go through numbers 2 1000 , test if prime or not.

i'm getting errors. pretty new if guide me in right direction great. using array large pre-set capacity better way of doing things?

many thanks, behzad

import java.util.arraydeque; import java.util.deque;  public class maths { public static void main (string[] arg) {              int x = 2;     arraydeque<integer> primes = new arraydeque<integer>(8);      for(int count = 2; count<1000; count++) {         if (x%count == 0) {             system.out.println("number not prime"); // if isn't prime, moves onto next number.             x = x + 1;             count = 2;         }          else if (x >1000) {             break;         }          else if (count == x - 1) {             system.out.println( x + " prime"); //this possibility singles out prime numbers             primes.add(x);             x = x + 1;                              // need find way add them memory.             count = 2;         }     }     system.out.println("searchfinished");     system.out.println(primes); } } 

there's no thing in java integer. proper 1 integer.

import java.util.arraydeque; public class myclass {   public static void main(string args[]) {      int x = 2;     deque<integer> primes = new arraydeque<integer>(8);      for(int count = 2; count<1000; count++) {       if (x%count == 0) {           system.out.println("number not prime"); // if isn't prime, moves onto next number.           x = x + 1;           count = 2;       } else if (x > 1000) {           break;       } else if (count == x - 1) {           system.out.println( x + " prime"); //this possibility singles out prime numbers           primes.add(x);           x = x + 1;                              // need find way add them memory.           count = 2;       }   }   system.out.println("searchfinished");    system.out.println(primes);  } } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -