Skip to content

Instantly share code, notes, and snippets.

@vaughan0
Forked from anonymous/gist:3888827
Created October 14, 2012 14:56
Show Gist options
  • Save vaughan0/3888835 to your computer and use it in GitHub Desktop.
Save vaughan0/3888835 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class exercise3 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("please enter a natural number.");
int naturalNumber = in.nextInt();
int count = 0 ;
while( naturalNumber !=1) {
if (naturalNumber%2 == 0)
naturalNumber = natualNumber/2;
count++ ;
else (naturalNumber%2 != 0)
naturalNumber = naturalNumber*3 +1;
count++ ;
}
System.out.println("The number of steps in told was " + count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment