Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Java19 {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. Scanner sc = new Scanner(System.in);
  7.  
  8. System.out.println("Enter number in range of 10 - 99:");
  9. int num = sc.nextInt();
  10.  
  11. while (num < 10 || num > 99) {
  12. System.out.println("Enter valid number in the range of 10 - 99!");
  13. num = sc.nextInt();
  14. }
  15.  
  16. int i = num;
  17.  
  18. while (i > 1) {
  19. if (i % 2 == 0) {
  20. i *= 0.5;
  21. System.out.print(i + " ");
  22. }
  23. if (i == 1) {
  24. break;
  25. }
  26. if (i % 2 != 0) {
  27. i = (i * 3) + 1;
  28. System.out.print(i + " ");
  29. }
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement