Write a Java program (Hailstone.java) that contains the main method and another method named minHailstoneValue. The minHailstoneValue method takes integers n and m as parameters and returns the minimum value in a hailstone sequence of length m that begins with n. The values of n and m are given by the user, and you may assume that the user will enter positive integers.
In a hailstone sequence, each value x is followed either by: (3x + 1) if x is odd
(x/2) if x is even
For example, if we start with 7 and we construct a sequence of length 10, we get: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20
In this case, the minimum value in the sequence is 7 (the number we started with).
Therefore, the following call: minHailstoneValue(7, 10) should return 7. If we instead construct a sequence of length 20, we get:
7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1 In this case, the minimum value in the sequence is 1.
Therefore, the call: minHailstoneValue(7, 20) should return 1. Example (user input underlined):
Hailstone sequence
Please enter a positive integer: 7
Please enter the length of the Hailstone sequence: 20
The min value in the sequence is 1
Attachments
No attachments uploaded
Tags
Clarifications
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'cramshark'; // required: replace example with your forum shortname
var disqus_identifier = '/production/143';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
Please enable JavaScript to view the comments powered by Disqus.

Source code is attached with preview
Attachments

hailstone.jpg (142 K)
Preview

Hailstone.java (1 K) Preview

Screenshots
Hailstone.java (1 K) Preview

if(currentValue % 2 == 0){
currentValue = currentValue / 2;
}else{
currentValue = 3 * currentValue + 1;
}
}
System.out.println("Hailstone sequence: " + sequence);
System.out.println("The minimum value in the sequence is " + minValue);
}
public static