Java number sequence program




















Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters. Copy link. Sign up for free to join this conversation on GitHub.

Already have an account? Sign in to comment. Viewed 3k times. Improve this question. Jake Jake 73 1 1 gold badge 3 3 silver badges 11 11 bronze badges. Add a comment. Active Oldest Votes. Your code has two problems: If you provide a non negative value, this will keep on going for ever since you are always only incrementing n. Even if you do supply a negative number, n would n need to become exactly 0 to stop. Improve this answer.

CubeJockey 2, 8 8 gold badges 22 22 silver badges 31 31 bronze badges. Use 'if' condition in place of 'while' loop. KishoreReddy KishoreReddy 2 2 gold badges 10 10 silver badges 20 20 bronze badges. Ya wright, you are changing the 'n' value in loop, that is also a reason for infinite loop. Better to use another local variable instead of changing the 'n' value. Let's say a traversal down a branch was occuring, and the search is currently at a node with key value , for example.

If the search entered the left subtree, then every successive key within the search must be less than , and if it entered the right subtree, then each key would be greater than Translating this logic towards a sequence of integers, lets say again the sequence is at an entry with value If the following number is less than , such as , then it means the search would be entering the left subtree.

Therefore, every following value in the sequence must be less than This logic stacks throughout the sequence, so if the number following was , we know the search entered the right subtree of Now, the following number after must be less than AND greater than Course Price View Course.

Free Software Development Course. Login details for this Free course will be emailed to you. Email ID. Contact No.



0コメント

  • 1000 / 1000