Question: Write a program to calculate and display the numbers in the Collatz sequence for a given number. Input: a positive whole number Output: all numbers
Write a program to calculate and display the numbers in the Collatz sequence for a given number. Input: a positive whole number Output: all numbers in the Collatz sequence Algorithm: Prompt the user for a positive whole number (you can do data validation if you wish) print the number repeat this until your number is 1 if your number is odd, multiply it by 3 and add 1 to the result if your number is even, divide it by 2 using integer division print the number (programing langugeis java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
