Java Exercise 1
To become more familiar programming in Java.
For this lab, you will write a simple program to test the collatz conjecture.
The conjecture states that if you take any natural number and, it's even, cut it in half, and if it's odd multiply it by 3 and add one, repeatedly, you'll eventually reach 1.
- Prompt the user to enter a number.
- Use the Scanner class to get an integer as input from the user.
Test that it is positive, if not get input again.
- Test if the number is even, if so divide it by 2.
- Otherwise, multiply by 3 and add 1.
- Do this until the number equals 1.
- Print out the number at each step.
When your program works, email the code to email@example.com.
Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.