Jump to content
xisto Community

aaronpatel

Members
  • Content Count

    4
  • Joined

  • Last visited

Everything posted by aaronpatel

  1. yup got it working...wat was wrong with my original code...it seems to be logically rite?Thanks for all your help...
  2. for some reason, the programming is not outputing anything...instead...cpu usage goes to a hundred percent...and its running at 2.93Ghz dual core without anything else running?LOL!
  3. hey guys....thanks alot...i thought cause it was in java category, it would be self-explanatory...
  4. An interesting problem in number theory is sometimes called the ânecklace problem.â This problem begins with two single-digit numbers. The next number is obtained by adding the first two numbers together and saving only the ones digit. This process is repeated until the ânecklaceâ closes by returning to the original two numbers. For example, if the starting two numbers are 1 and 8, twelve steps are required to close the necklace: 1 8 9 7 6 3 9 2 1 3 4 7 1 8 Create a Necklace application that prompts the user for two single-digit integers and then displays the sequence and the number of steps taken. The application output should look similar to: I can't seem to figure it out. Any help? I tried doing this, but there is no output. It seems to just freeze my computer. public class Necklace { public static void main(String[] args) { int originalFirstNumber = IBIO.inputInt("Enter the first starting number: "); int originalSecondNumber = IBIO.inputInt("Enter the second starting number: "); System.out.println(necklace(originalFirstNumber, originalSecondNumber)); } private static String necklace(int originalFirstNumber,int originalSecondNumber) { String output; int firstNumber = originalFirstNumber; int secondNumber = originalSecondNumber; do{ output = originalFirstNumber + " " + originalSecondNumber + " "; int result = firstNumber + secondNumber; String resultInString = " " + result; int lastNumberOfResult = resultInString.charAt(resultInString.length() - 1); firstNumber = secondNumber; secondNumber = lastNumberOfResult; output += secondNumber + " "; } while(!(firstNumber == originalFirstNumber) && !(secondNumber == originalSecondNumber)); return output; }} Thanks.
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.