Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Project1
- {
- public static void main(String[] args)
- {
- Scanner stdin = new Scanner (System.in);
- int input;
- int i = 0;
- int output = 0;
- System.out.println("Enter an integer: ");
- input = stdin.nextInt();
- while(output != 1)
- {
- while(input % 2 != 0)
- {
- output = 3*input + 1;
- System.out.println(output);
- i++;
- }
- while(input % 2 == 0)
- {
- output = input / 2;
- System.out.println(output);
- i++;
- }
- }
- System.out.println("It took "+i+ "iterations.");
- }
- }
Add Comment
Please, Sign In to add comment