Please complete the following program according to the specification given. Partial credit will be given for incomplete answers, so provide as much of the answer as you can. Remember that all program segments are to be written in JAVA.
2.Write a method collatz() which takes an argument int n and prints the collatz sequence for n with commas (“,”) between each number. The collatz sequence is defined as follows.
If the current term is even, the next term is the current term / 2. Otherwise the next term is(3* current term) * 1. The sequence ends when the current term is 1. Note that the first term (n) and the last term (always 1) are printed. You may assume n is a positive integer.
Example:
collatz (1) prints: 1
collatz (4) prints: 4,2,1
collatz(5) prints: 5,16,8,4,2,1