Guest User

Untitled

a guest
Jul 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import java.util.*;
  2. public class Project1
  3. {
  4. public static void main(String[] args)
  5. {
  6. Scanner stdin = new Scanner (System.in);
  7. int input;
  8. int i = 0;
  9. int output = 0;
  10.  
  11. System.out.println("Enter an integer: ");
  12. input = stdin.nextInt();
  13.  
  14. while(output != 1)
  15. {
  16. while(input % 2 != 0)
  17. {
  18. output = 3*input + 1;
  19. System.out.println(output);
  20. i++;
  21. }
  22. while(input % 2 == 0)
  23. {
  24. output = input / 2;
  25. System.out.println(output);
  26. i++;
  27. }
  28. }
  29. System.out.println("It took "+i+ "iterations.");
  30. }
  31. }
Add Comment
Please, Sign In to add comment