HailStone sequence

Currently HailStone sequence has not been proven whether there are poor, so it is not necessarily an algorithm.

* Hailstone sequence 
when * n = 1, return 1;
* and is an even number, {n} ∪ {n / 2} when the n-> 1
* n-> 1 and is an odd number, {n} ∪ {3n + 1}

/ ** 
     * Hailstone sequence 
     * n = 1, return 1; 
     and a is an even number, {n} ∪ {n / 2} when the * n> 1 
     * n> 1 and is an odd number, {n} ∪ {3n }. 1 + 
     * 
     * @param n- 
     * @return 
     * / 
    public  static String Hailstone ( int n-) { 
        the StringBuilder STR = new new the StringBuilder ();
         the while (n->. 1 ) { 
            str.append (n- + "," );
             IF ( % 2 == 0 n- ) { 
                n- = n-/ 2 ; 
            } the else  {
                n-= 3 * n + 1;
            }
        }
        if (n == 1) {
            str.append(n + ", ");
        }
        return str.substring(0, str.length() - 2);
    }

 

Guess you like

Origin www.cnblogs.com/Latiny/p/11016563.html