i used this code to generate a int N. I do this using (even)n=n/2 and (odd) n=3n+1 until n becomes 1. i use a System.out.println(n); to show the results, but what if i only wanted to show that last 4 numbers in the sequence... any suggestions.. thanks in advance annie
Code:int n = 0; System.out.println("Please enter a number less than 100,000"); KBI.pause(); n = KBI.getint(); while(n != 1) { System.out.print(n + " "); if(n % 2 == 0) n = n / 2; else n = 3 * n + 1; } System.out.println(n);




Reply With Quote