Find primes of a number implementing queue.  Need help debug!

This class "Prime" is to find primes of a number using eratosthenes algorithm implementing queue data structure. I have difficulty removing numbers in the list that is the multiple of the next prime. Since I am only allow to use queue, I have a problem iterate through the list. The problem occurs inside my while loop, but I think it's the loop's condition that causes the problem. The program enters an endless loop when it's run; Anybody famaliar with eratosthenes algorithm; please give me some pointers to debug my program. Thanks
import java.lang.Integer;
import java.lang.Math;
public class Prime
public static void main(String[] args)
int input = 0;
System.out.print("Enter a max value for find its primes>> ");
Scanner in = new Scanner(System.in);
input = in.nextInt();
printAllPrimes(input);
public static void printAllPrimes(int max)
LinkedQueue qNum = new LinkedQueue(); //num list
LinkedQueue qPrime = new LinkedQueue(); //prime list
Integer object = new Integer(2);
Integer temp;
for(int i = 2; i<=max; i++)
Integer num = new Integer(i);
qNum.enqueue(num);
while(object.intValue() <= Math.sqrt(max))
object = (Integer)(qNum.dequeue());
qPrime.enqueue(object);
temp = (Integer)(qNum.first());
while(!qnum.isEmpty())
if((temp.intValue() % object.intValue() == 0))
qNum.dequeue();
//transfer all values of qNum to qPrime
//print qPrime
********************Here is the LinkedQueue implementation that I use with my Prime class*********************
// LinkedQueue.java Authors: Lewis/Chase
// Represents a linked implementation of a queue.
//package jss2;
import jss2.exceptions.*;
public class LinkedQueue implements QueueADT
private int count;
private LinearNode front, rear;
// Creates an empty queue.
public LinkedQueue()
count = 0;
front = rear = null;
// Adds the specified element to the rear of the queue.
public void enqueue (Object element)
LinearNode node = new LinearNode(element);
if (isEmpty())
front = node;
else
rear.setNext (node);
rear = node;
count++;
// Removes the element at the front of the queue and returns a
// reference to it. Throws an EmptyCollectionException if the
// queue is empty.
public Object dequeue() throws EmptyCollectionException
if (isEmpty())
throw new EmptyCollectionException ("queue");
Object result = front.getElement();
front = front.getNext();
count--;
if (isEmpty())
rear = null;
return result;
// Returns a reference to the element at the front of the queue.
// The element is not removed from the queue. Throws an
// EmptyCollectionException if the queue is empty.
public Object first() throws EmptyCollectionException
if (isEmpty())
throw new EmptyCollectionException ("queue");
return front.getElement();
// Returns true if this queue is empty and false otherwise.
public boolean isEmpty()
return (count == 0);
// Returns the number of elements currently in this queue.
public int size()
return count;
// Returns a string representation of this queue.
public String toString()
String result = "";
LinearNode current = front;
while (current != null)
result = result + (current.getElement()).toString() + "\n";
current = current.getNext();
return result;

never mind; it finally got it figured out. Thanks

Similar Messages

  • Could Not Find Installation Information for this Machine" I need Help!

    i accidentaly erased the main drive and now i am trying hard to reinstal the OS X again but i constantly keep seeing this "could not find installation information for this machine" i need help....

    hello,
    I had the same problem yesterday, just go to a place with a better internet conncetion, it will work fine...
    good luck

  • Currently use acrobat 6.  getting box that states: can't find adobe pdf resource files... need help

    Getting a box that states: can't find
    adobe pdf resource files... need help!!!

    I get a similar error, but only under the following conditions:  I must be printing to the Adobe PDF printer and printing multiple pages, one at a time, and then it only happens on the second and subsequent print attempts.  That is to say, the first page prints just fine and this just started yesterday afternoon. The specific file referenced in the error does not exist, but why would it work the first time and not the second?  Since it only started yesterday, I tried uninstalling and reinstalling this morning, but it made no difference.  I don't see anything under print properties like job-options and it is a single user, unshared printer.  Thoughts?  I understand the same thing is happening in at least one other of our locations, but no one there has looked into it yet.  This is a BIG problem for me, however, and I need to find an answer quickly.

  • Hi,i have the new ipad 16gb it was working fine till i went to download te new i tunes and the apple mobile device recovery mode my windows pc cant find the software to download it i need help because my ipad wont work i only see the itunes en usb symbol.

    i have the new ipad 16gb it was working fine till i went to download the new itunes and the apple mobile device recovery mode my windows pc cant find the software to download it i need help because my ipad wont work i only see the itunes and usb symbol can anybody help me.

    Try these instructions:
    http://support.apple.com/kb/TS3281
    You may also have to go to the link in the bottom paragraph if the first page instructions do not work.

  • HT4061 Serial number not recognized need help

    Serial number not recognized need help
    <Edited by Host>

    Not recognized where? And what sort of help are you hoping for from us, your fellow users?

  • Hi..i am trying to login i message but i cant access ,it thing i forgot my password number, please i need help,how i can reset new password number. please i need help.

    hi..i am trying to login i message but i cant access ,it thing i forgot my password number, please i need help,how i can reset new password number. please i need help.

    Go here.
    Good luck,
    Clinton

  • I Purchased upgrade but do not have old serial number...need help

    I bought a new PC and want to move my adobe acrobat 9.0 Pro to my new laptop but the serial number for my product is for an upgrade (which was done on my previous PC I no longer have).
    How can I activate my Acrobat 9.0 Pro without having my old serial number?
    Need help.    

    http://helpx.adobe.com/x-productkb/global/find-serial-number.html#adobeproductdownload

  • HT201250 I am very frustrated. New to iMac products. Just bought a 27" iMac two days ago. Received no manual, no booklet with ID registration number, etc. Need help migrating PC to iMac. How do I get in touch?

    Need help migrating pc to imac. Do not have manual. Trying to get infornation online, but, cannot get an answer.
    I have downloaded pc migration assistant to pc windows 8 pro. Was able to get imac to finally give me "the number"
    Did the same with pc received number once, not same as imac. Pop up window with info dissappers and cannot recover
    What am I doing wrong? Paid extra for extended support package and it took hours to finally get it registered and approved.
    However, no help. Yikes, I feel like a make another great mistake!

    First: If you purchased AppleCare you should call back at 1-800-APL-CARE and ask for further assistance.  You'll want to learn how to retrieve your operating system version and your IMac's serial number as you'll need these for when you call AppleCare:
    Click on the Black Apple in the top left hand corner of your Imac's physical monitor
    Click on About this Mac from the drop down menu
    Below the silver Apple and "OS X" it will say "Version 10.x.x"  (If this number is not 10.8.4, run Software Update by hitting the button marked "Software Update")
    Click on this number twice in a row.  This is your machine's serial number.  (zeros can be used; the letter "O" is never used).
    http://support.apple.com/kb/HT1349 for details how to find serial numbers on Apple products
    If you have an Apple ID (you can create one at appleid.apple.com), you can login to supportprofile.apple.com, register an Apple product, and sign up for VoicePass, which, if you give your product a name e.g. Maria's Imac, you can speak that over the phone and skip having to give the serial number when you call. 
    If you have an Apple ID, you can also call AppleCare and ask them to activate VoicePass.
    This is the link for your tech specs: http://support.apple.com/kb/SP667
    This is the link for your quick start guide: http://manuals.info.apple.com/en_US/imac_late2012_quickstart.pdf
    This is the link for important product information: http://manuals.info.apple.com/en_US/imac_late2012_quickstart.pdf
    Second: this is an educated guess: Your new Imac and your PC need to be either on the same wifi network or you need to connect them physically with an Ethernet cable (available at Radio Shack, Wal Mart, etc).  My guess is that they are not, and so your IMac and PC are not talking to each other.  That might be why you are seeing a different code on the PC.
    Time Machine would not be relevant to your issue.  http://support.apple.com/kb/HT4796 is the link to relevant instructions, however it left out some housekeeping you should do on your Imac before you begin a migration
    Run Software Update on the IMac to confirm that the latest updates are installed.
    On the IMac, make sure that you have the latest versions of any third-party software.
    On the source Mac, open System Preferences, click Sharing, and make sure there is a name in the Computer Name field.
    Do not let either computer go to sleep while you are attempting to migrate. To disable sleep on the IMac
    Choose System Preferences from the Apple () menu.
    Choose Energy Saver from the View menu.
    Adjust the "Computer sleep:" slider to Never. (Change this back after the migration is done).
    You can adjust "Display Sleep" to a few minutes - this won't affect the migration
    Uncheck the box if checked next to "Put Hard Disks to sleep when possible"
    I don't know Windows 8 but this link looks promising as to how to disable sleep: http://techmell.net/how-to/disable-enable-sleep-mode-hibernate-windows-8/
    Once you've done this, either connect both Mac and PC to the same wifi network and surf the web with each to confirm that connection is working - or connect them to each other with an Ethernet cable. 
    Then relaunch Migration Assistant on your Imac and your PC, and follow the instructions in http://support.apple.com/kb/HT4796 starting with your IMac, or call AppleCare back. 
    Understand that if you have further issues, you'll need to help AppleCare help you by:
    walking them through the steps you've taken in Migration Assistant
    letting them guide you as they isolate the issue to either:
    The Imac's software
    The IMac's hardware
    The PC's software
    The PC's hardware
    Firewall settings (maybe - especially if 3rd party firewalls are installed)
    The wifi connection, if used
    The ethernet connection, if used
    I think the issue is likely what I guessed, or it's a software issue.
    To learn more about your new Mac, I recommend this link: http://www.apple.com/support/imac/intel/
    And this book: http://www.amazon.com/books/dp/0789749890
    I am a technical support professional who troubleshoots Macs all day long.  I do this for a living.  The book above is the most accurate, and easy to understand book I've seen with respect to using Mountain Lion and its various applications.  It's for a MacBook but the focus is on the software which is why I recommend it.
    Don't feel like you have to rush to upgrade to OS X Mavericks.  In fact, you should always confirm both all the hardware and software you use is compatible with any new operating system before you upgrade.  And ask yourself: "why do I need it now?"  Because it's new is not a good answer.
    In the future, specifying any troubleshooting others have done will help those on these boards help you.  Also, don't let a specific issue lead you to assume you've made an all-encompassing mistake.  It's just one issue, and it's resolvable.
    And everyone else: giving a dozen recommendations for reading will only leave the petitioner bewildered.  Start with three.  And try responding with a hypothesis as to what's causing the primary problem!

  • I brought Quicktime 7 Pro for Windows 7 Pro and it did not electronically download or I can't find it anywhere on my computer.  Need help.

    I brought Quicktime 7 Pro for Windows 7 Pro and it did not electronically download or I can't find it anywhere on my computer.  Need help

    Apple - QuickTime - Download
    Download and install the free version and apply your key to unlock the Pro features.

  • My MacBookPro can't find my buetooth device from my speakers need help

    My MacBookPro can't find my buetooth device from my speakers need help

    Hi there nellyfau,
    You may find the troubleshooting steps in the article below helpful.
    Bluetooth Quick Assist
    http://support.apple.com/kb/ht1153
    -Griff W. 

  • My iPhone 4S randomly loses contacts, even if I have re-entered them into the phone. Tonight 12 of the contacts I text to are no longer in my address book. Their text window just shows their phone number. I need help.

    I need help with this problem, is there a solution?

    Mine continue to do the same thing. I have stopped my contacts from syncing with icloud (not that they were anyways) and re-entered a bunch. 5 minutes later some are missing phone numbers or are completely missing altogether. What is causing this and how can I stop it??

  • Am I able to find my iTunes serial number? I need it for the problem solving as my problem is solely bad on my iTunes.

    For the Apple problem solving section I need a serial number, my issue is that my problem regards missing contents within my iTunes. Do I have an iTunes serial number? And if so, where can I locate it? If there is not a serial number for iTunes, advice on what to do next is much appreciated.

    iTunes has no serial number. If you are trying to get to Apple phone support, that is linked to the purchase of Apple hardware, so you need to enter in the serial number of an Apple device. Otherwise, for assistance with problems with iTunes itself you would need to call Apple Support and they would almost certainly charge for the call. I would instead suggest you post the issue you're trying to address here in detail. Someone here can probably offer suggestions.
    If your issue is with the iTunes Store, not the iTunes application, go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report your issue to the iTunes Store.
    Regards.

  • How to implement this need help

    I created a datacontrol for a named query which (using Ejb entity beans) which accepted a employee id and click on find show me the respected employee details in a table.
    case 1: In one single page
    when i added the form consisting of a single text box , button and the table to show the result of the find method in one single page it worked out perfectly,,,
    case 2 : using 2 different pages
    But then i tried adding only the form in one page named page1 and and the table to show the result in another page i.e page2 , Also in the command action of find button of page1 i asked it to redirect to page 2 and show result . But it never showed me any results..
    Question :
    1) How to implement case2 i.e to have a form on one page and the resultant table to be show on another page i.e When users sees first page he adds the employee id in text box and clicks find .The user then needs to be redirected to page2 and the result of search should be shown in table...
    Can anyone guide me over this... ???

    Hi,
    you use a method on the EJB that takes a argument (e.g. the employee ID). You then put the method result set on page 2 (the method argument shall be pointed to a request or session attribute using EL : #{sessionScope.EmployeeId}
    On the search page - when the user hits the search button - you set the attribute "EmployeeId" in the session before navigating to the next page
    Frank

  • Software & registration number trashed..NEED help!!

    I bought and installed iwork '06 yesterday and trashed iwork '05. Weeks ago, I trashed the paper boxes/materials came with iwork '05 that means, I trashed the software (iwork '05) registration number required for software installation. Is there any way to get back the software registration number from any hidden corner/source? Or, is there any source where I can send email requesting for the registration number? If nothing is possible, I may have to trash the iwork'05 DVD that will be painful.Though iwork '06 is running fine so far, I may need it, for which I paid, in future. Can anybody help me to retrieve the lost registration keys? I do appreciate your help. Thanks a lot.
    PowerBook G4 12"   Mac OS X (10.4.5)  

    Dennis,
    Thank you for your helpful suggestion. I will follow your way to be more organised with the installed softwares from now and onward. But, you see, as I remember as a former Windows user, the software serial number is readily availale in a text file (may be in a 'Read me' file or different) in the installer CD/DVD. This is really useful. Once someone buys a software...s/he deserves everything useful to the user in relation to software installation and usage MUST be documented in both CD/DVD and paper. I believe Apple smart softwares are lacking this feature, which is surely helpful to their smart users. Where there are users guides in the CD/DVD, the serial number is not...this is certaily a lacking..isnt it???!!!
    PowerBook G4 12"   Mac OS X (10.4.5)  

  • My account is not working with my credit card.  I wanted to "CALL" someone but was told there is NO phone number.  I need help to activate (REactivate) my account.

    Need assistance.  I would prefer to actually TALK to someone to fix this problem.  Is there a phone number to call to actually fix my iTunes Store account billing issues?

    There is no one to talk to.
    Contact itunes support:
    http://www.apple.com/support/itunes

Maybe you are looking for