-
-
Save vaughan0/3888835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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