Results 1 to 4 of 4
  1. #1
    Confushous is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Java EKG program

    I am having trouble starting a program to compute the ekg. can anyone help

    • Every number after that is the smallest number that is not in the sequence, and shares a factor larger than 1 with the last number



    The first 10 numbers in the EKG sequence are

    1,2,4,6,3,9,12,8,10,5



    The program you turn in is to read in an integer n and compute and print the first n terms in the EKG sequence.

    Your program should also include a function (or method) to compute GCD using Euclid’s algorithm (which is found on page 4 of your book). You are to use this function to determine if a candidate shares a factor larger than 1 with the last number in the sequence.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java EKG program

    Are the numbers 1 and 2 supposed to be the first two numbers in that sequence by definition?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Confushous is offline Member
    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    Default Re: Java EKG program

    Quote Originally Posted by Confushous View Post
    I am having trouble starting a program to compute the ekg. can anyone help

    • Every number after that is the smallest number that is not in the sequence, and shares a factor larger than 1 with the last number



    The first 10 numbers in the EKG sequence are

    1,2,4,6,3,9,12,8,10,5



    The program you turn in is to read in an integer n and compute and print the first n terms in the EKG sequence.

    Your program should also include a function (or method) to compute GCD using Euclid’s algorithm (which is found on page 4 of your book). You are to use this function to determine if a candidate shares a factor larger than 1 with the last number in the sequence.

    Yes 1 and 2 are always the first two numbers

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: Java EKG program

    What's the problem then? Try each number n: if it's not in the set already and the gcd(lastNumber, n) > 1, add n to the set and repeat.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 04:13 AM
  2. Replies: 4
    Last Post: 07-30-2010, 12:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •