Creating a Program for Identifying Prime Numbers

I am beginning computer science major and I am completely lost with this. Can anyone help me figure this out?
Due: Monday, January 14, 10:00 am
Write a program that calculates all prime numbers less than 10,000. The program works as follows:
1. Create a main method, and a method called ArrayList< Integer > sieve( int n ), which returns a list with all the prime numbers less than n. The main method calls sieve( 10,000 ), and prints out the results.
2. Inside of sieve(), do the following:
a. Call method createTrueArray( n ) to create a boolean array of size n.
b. Set cells 0 and 1 of the array to false. Each cell in the array represents a number, the boolean value represents whether it is prime or not. We start by assuming that all numbers greater or equal 2 are prime, and then we remove the ones that are not.
c. Loop over the array, starting at index 2.
d. First, remove all multiples of 2, by setting the values for 4, 6, 8, ... to false.
e. Then, look for the next number still marked true (in this case 3), and set all its multiples to false.
f. Repeat with all numbers that are marked true. When you are done, only prime numbers will be marked true.
g. Call method booleanArrayToIntList() to return a list of integers that contains the primes.
3. Method boolean[] createTrueArray( int n ) creates a boolean array of size n and initializes all its values to true.
4. Method ArrayList< Integer > booleanArrayToIntList( boolean[] booleans ) loops through booleans, and for each true value, it adds the corresponding number to a list. Finally, it returns the list.

brriney wrote:
I am beginning computer science major and I am completely lost with this. Can anyone help me figure this out?
Due: Monday, January 14, 10:00 am This is what I felt like typing in response to your post:
Thank you for posting your assignment and telling us when it is due. Now please sit back, kick your feet up, have some donuts while we work on your homework.
But I won't ;). Let me tell you just this. Dumping the assignment here without showing any work (and giving a deadline no less!) is tantamount to asking the volunteers here to do your assignment and will only get you flamed. We will help those that show some effort; so please please show your work and ask specific questions regarding your code.
Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, either use the "code" button at the top of the forum Message editor or place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
&#91;code]
  // your code block goes here.
&#91;/code]

Similar Messages

  • Is it possible to create a program for embedded system

    Is it possible to create a program for embedded system?

    Yes. Many solutions.
    1 = http://jcx.systronix.com/
    2 = http://www.harbaum.org/till/nanovm/index.shtml (see links to Asuro)
    And many more but I'm too lazy too look them for you ...
    Dan

  • Creating Z program for T code FBRA (resetting cleared item)

    HI ABAP Gurus,
    I have a requirement , please Help me.
    One of my client Has executed APP program. through with 100 items are cleared. later they identified those invoice should not be cleared. To Reset this cleared item we have T code FBRA through which we can reset single line item each time.
    So we need to develop a new program for Resetting all the items at one instance. Please guide how configure this??
    Thanks in Advance
    Babu

    Yes AFAIK there is no standard report so you have to create your own with usage of FM POSTING_INTERFACE_RESET_CLEAR (*) "Jus" change the parameter of FBRA into SELECT-OPTIONS.
    Regards,
    Raymond
    (*) FI Financial Accounting: Data Transfer Workbench; Accounting Documents: Data Transfer Workbench, Using the Internal Posting Interface.

  • Problem in creating include program for customer exit for BC425_01

    Hi,
         I want to write a customer exit for transaction BC425_01. For identifying the include program for exit , i go to System->Status.There I double click on the program name(GUI).Then I perform a 'FIND' in main program for 'customer-function' keyword. I get 3 search results with "CALL CUSTOMER-FUNCTION '001' " , "CALL CUSTOMER-FUNCTION '002' " , "CALL CUSTOMER-FUNCTION '003' ".
    Now i double click on CALL CUSTOMER-FUNCTION '001'  and i am taken to the code of program where this function is called in MODULE cust_check INPUT. I double click on CALL CUSTOMER-FUNCTION '001'  and then I am taken to the function module code which contains a single statement 'INCLUDE ZXBC425G01U01 .' .
    Now I double click on this include program so that I can write my own code. But when i double click on it , a message displayed 'Program names ZX.. are reserved for includes of exit function groups'. Hence I am not able to creates this include program and write my coding.
    Kindly Help
    THANKS

    Hi Amber,
    Then you click enter button.It is asking to create object with that include name ZXBC425G01U01 in a pop-up.You  should select YES option.It will ask package . Give the package name and save.Then include program is created and allowed you to write your own code.
    Thanks,
    Prasad GVK.

  • How to create a form for identifying people in a photo?

    I have a group photo of about 60 people that I have imported into Acrobat Pro XI.  I would like to be able to send this photo pdf to others to get help identifying all of the people in the photo.  None of the recipients is likely to know all of the people, but it's likely that the contributions of all will end up identifying all of the people in the photo. 
    It seems like I ought to be able to create a form based on that photo pdf that includes a blank next to each person and that I can email to others to fill in as many of the blanks as they each can and return the form to me. 
    However, I've never created a form before, so I'm not sure how to get started and go about creating it, including which field type to use, how to collect the data when the completed forms come back, etc. 
    Has anyone done this sort of thing before? 
    Thanks

    It  might be better for people to use the various commenting tools that are available. If you Reader-enable the document, they will be able to use the various markup tools to add text and otherwise annotate, which is more flexible than form fields. For example:
    But you may have to include some instructions.

  • Creating java program that orders 3 numbers in ascending order using if els

    Does anyone know what code to use for creating a java program that uses the if else operators to order 3 variables in ascending order?

    nar0122 wrote:
    correct on the homework assumption...you have a good nose...the thing is...i know i need to make an if statement saying if a is less than b, and a is less than c...print a first...but how do i get it to "print a" first? if a is less than c and b...and so on for b and c? sorry if that was confusing...
    int a = ..., b = ..., c = ...;
    if(a > b AND a > c) {
      print a
      if(b > c) {
        print b, print c
      } else {
        print c, print b
    etc.

  • Creating .exe program for windows

    How can I create an executable program (.exe) for windows. I tried using Excelsior-JET compiler but it doesn't increase the efficiency of program. Is there some other standard method for creating .exe
    Also if u suggest me to use JIT, do tell me some details about how to use it.

    Hey guys don't u need to develop application for windows.

  • How to create a program for train reservation in java

    hi
    anyone plz help me
    my problem is that:
    design a program that can book the seats in a train for the customers
    and a condition is a person cant book more than 5 seats
    Total no of seats is 67
    13 rows of 5 seats
    and in last row there are two seats

    Implied request for your homework to be done foryou
    is denied.or is it?Slight correction:
    Implied request for your homework to be done for you
    by anyone in their right mind and competent is
    denied.You're the one that can't even follow the scope of objects in java. I'm certainly more competent than you are.

  • Can i create  client program for a servlet(without browser)

    Hai All,
        I have to call a servlet in my normal java program.Please send me code.
    Thanks
    Madhu

    Hi,
    Try getting a URL connection to the servelt and send the request as
    import java.net.URL;                     // New addition
    import com.oreilly.servlet.HttpMessage;  // A support class, shown later
      private String getServlet() {
        try {
          // Construct a URL referring to the servlet
          URL url = new URL(getCodeBase(), "/servlet/myServlet");
          // Create a com.oreilly.servlet.HttpMessage to communicate with that URL
          HttpMessage msg = new HttpMessage(url);
          // Send a GET message to the servlet, with no query string
          // Get the response as an InputStream
          InputStream in = msg.sendGetMessage();
          // Wrap the InputStream with a DataInputStream
          DataInputStream result =
            new DataInputStream(new BufferedInputStream(in));
          // Read the first line of the response, which should be
          // a string representation of the current time
          String response = result.readLine();
          // Close the InputStream
          in.close();
          // Return the retrieved time
          return response;
        catch (Exception e) {
          // If there was a problem, print to System.out
          // (typically the Java console) and return null
          e.printStackTrace();
          return null;
    Regards,
    Uma
    Message was edited by: Uma Maheswari

  • Create a program for Automatic calculation of Interest on arrears for Custo

    Hello Experts,
    Please Check the below requirement and guide me according ly..
    Upto now our client is preparing the interest manually in excel and later they issue the invoice in Finance module (DR document) and attach the paper with the calculation.
    Now they would like to have an automatic process for all the customers  with the exception of the Intercompany.
    The keys indicator will be:
    Interest term:
    Capital     * Days of delay/ 360     * interest rate(see table)     
                      (Legend days of delay= new duedate agreed - original duedate of invoice)
    -Calculate interest based on line items (open items and items cleared with a payment)
    -Calendar: 360 days
    -Transfer days: zero
    -Tolerance days: zero
    -Interest processing: amount limit  20u20AC
    -Posting;
          Terms of payment: blank (to be define case by case)
          Tax code: VJ NS Art 15 I comma
    The interest will be registered only if we have posted the invoice in the system.
    I confirm that the account number will be  5401000 cost center     C010100238
    Please suggest me how we can develop a programme
    Thanks in advance,
    Satya

    Hi,
    You need to configure INTEREST CALCULATION setup in system in order to automate the posting interest to customers / vendors.
    [Interest Calculation |http://wiki.sdn.sap.com/wiki/display/ERPFI/Interest+Calculation]
    Regards,
    Srinu

  • While creating Goods Receipt for multiple serial numbers it is generating an internal error

    Error:Internal error (-5002) occurred  [ 131-183]
    we are using version SAP B1 9.0 PL 4
    The code which we are using.
           Dim oPDN As SAPbobsCOM.Documents
           oPDN = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes)
                         Dim serno As String = "SH-A1,SH-A2"
                        Dim sernoval As String() = serno.Split(",")
                        Dim mnfser As String = "SH-B1,SH-B2"
                        Dim mnfserval As String() = mnfser.Split(",")
                        For k = 0 To sernoval.Length - 1
                            oPDN.Lines.SerialNumbers.InternalSerialNumber = sernoval(k).Trim
                            oPDN.Lines.SerialNumbers.ManufacturerSerialNumber = mnfserval(k).Trim
                            oPDN.Lines.SerialNumbers.Quantity = linedetails(iRowNo).Quantity
                        Next
                    oPDN.CardCode = "C232323"
                    oPDN.Lines.ItemCode = "A00004"
                    'oGR.Lines.LineNum = 0
                    oPDN.Lines.BaseLine = 1
                    oPDN.Lines.BaseEntry = 202
                    'oGR.Lines.BaseRef = 203
                    oPDN.Lines.BaseType = 20
                    oPDN.Lines.Quantity = 1
                    oPDN.Lines.UnitPrice = 2
                    oPDN.Lines.WarehouseCode = '01'
                 oPDN.Lines.Add()
                 lRetCode = oPDN.Add

    Hi Vasanth,
    I'm not really fluent in VB, but I think that a SerialNumbers.Add() and SerialNumbers.SetCurrentLine() are missing before the Next
    Regards,
    Eric

  • How to create a program for sequential task performing?

    A particular task has to be performed first then only permission is given to perform the next task?
    Can it be performed on LabVIEW?
    Solved!
    Go to Solution.

    LabVIEW ships with examples. You should look up the examples and search for the state machine structure. It will show you details on how to structure your code to allow for the exact process that you need to use to be successful. Try to look at that code and then come back when you have some code for us to review. This allows you to learn and us to guide you through how to use things properly.
    We like it more when you have specific questions like I can not get this to work or I do not understand how this works...
    I hope you help yourself so we can help you better.
    Tim
    Johnson Controls
    Holland Michigan

  • How to create a customer program for "PPMOD"feature(pe03)?

    Hi,
    I want to create customer program for "PPMOD"feature(tcode:pe03),who can tell me the steps? (ECC6.0)
    thanks a lot?
    Olivia Yang

    Hi,
    /1PAPA/FEAT610PPMOD the generated program for the feature.
    You are forbidden to change this generated program. Ideally whatever logic regarding the feature needs to be put through pe03 tcode of feature and not in the program.
    Still if there are any changes that need to be done to the program you can enhance the program.
    To enhance the program you need to go to se 38 and open this program and press Shift + F4
    Then Goto->Enhancement operations->Show implicit enhancement operations
    Then go to yellow line right click on mouse and Enhancement implementation->Create
    And put your own code in the implementation.
    Regards,
    Divya

  • Enable to create ldt file for specific program using FNDLOAD submit request

    hi ALL ,
    i am trying to create .ldt file for specific program but the things is that following program creating .ldt file for all the program which are available on instance .
    please suggest me if i did anything wrong in my code ...
    DECLARE
    req_id fnd_concurrent_requests.request_id%TYPE;
    BEGIN
    fnd_global.apps_initialize (user_id => 1012001,
    resp_id => 20420,
    resp_appl_id => 1
    req_id :=
    fnd_request.submit_request
    (application => 'FND',
    program => 'FNDLOAD',
    description => NULL,
    start_time => NULL,
    sub_request => FALSE,
    argument1 => 'DOWNLOAD' ---Mode - UPLOAD
    argument2 => '@fnd:patch/115/import/afcpprog.lct'
    -- -LCT File
    argument3 => '/tmp/concqueues.ldt' -- -
    argument4 => 'PROGRAM',
    argument5 => 'XXFUJI'
    ,argument6 => 'XXSAG_FILE_DATA'
    DBMS_OUTPUT.put_line ('req_id= ' || req_id);
    COMMIT;
    END;
    thanks in advance
    sagar

    thanks for your reply ... Alex
    ... but... no i don't wanna create concurrent program for fndload neither i want to use FNDLOAD script ... the above FNDLOAD Submit request program worked for me and using that i have created ldt but my problem is that program is creating ldt for all program which are registered , it's not picking my my file which i pass as a parameter ...please have look into my code ...
    and please suggest me ..
    thanks
    sagar

  • Help me getting prime numbers

    hi,
    can anyone help me with this i'm newbie and can't figure the solution out
    "Write a multithreaded Java program that outputs prime numbers.
    This program should work as follows: The user will run the program
    and will enter a number on the command line The program will then
    create a separate thread that outputs all the prime numbers less than or
    equal to the number that the user entered".
    thx in advance

    prime numbers are numbers that can only be divided by 1 and itself
    1,2,3,5,7,9,11,...
    maybe the only condition u can check is whether it is divideable by 2 , 3 or 5 but you have to exclude 2 ,3 and 5
    since all numbers (except prime numbers) are made up from multiplication from 2, 3 ,and 5, you can use that logic
    example :
    4 <-- divideable by 2 <-- not prime
    9 <-- divideable by 3 <-- not prime
    23 <-- not divideable by 2 , 3 , or 5 <-- then it is prime
    if(nums == 2 || nums == 3 || nums == 5)
         //it is prime for sure
    else if(nums % 2 == 0 || nums % 3 == 0 || nums % 5 == 0)
         //it is not prime
    else
       // it is prime number

Maybe you are looking for