Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Collatz conjecture

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Collatz conjecture

    ok, so I am building a program that calculates a number that user enter, with the collatz conjecture principles.

    A random number is entered, if it is an even number it shall be divided by 2,if it is an odd number it must be multiplied by 3 + 1 and then divided by 2.. This goes in a loop until the number is 1. I have already found the method for this, but I do not get the number to not be negative.

    question is: how do I prevent the number from going over to the negative side?
    First i tried : while(X>1) but that doesent work, so I thought while(X!=1) but that doesent work either. And when i enter the number 837799 the computer goes in to a endless loop..

    I DONT WANT THE COMPLETE ANSWER, just a nod in the right direction!
    Last edited by Ripcurl; October 27th, 2010 at 07:26 AM. Reason: EDIT: Never mind, figuerd it out! :D