1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Java

Connected

Exercise

Collatz

A fun little fact of mathematics is that simple rules can give rise to big consequences. For example, the Collatz Conjecture asks whether two simple rules can reduce any integer to 1.
Its statement is usually the following :

  • For even numbers, halve by 2
  • For odd numbers, multiply by 3, then add 1
    Let's test it out !

Note: If you experience code timeouts, carefully check the logic of the if-else statement (or the Hint).

Instructions

100 XP
  • Enter the appropriate termination condition.
  • Call a method to check if n is even.
  • Handle the odd case correctly - this should only trigger if the original n is odd.