Advertisement
Joe27

Untitled

Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package razvarov_harjutus7;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author AR
  13. */
  14. public class Razvarov_harjutus7_2 {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. int i,n;
  21. Scanner scan = new Scanner(System.in);
  22.  
  23. int a = scan.nextInt();
  24. int b = scan.nextInt();
  25. for (i=a; i<=b; i++) {
  26. n = i;
  27. System.out.printf("-> %d ", n);
  28. while (n != 1) {
  29. if (n%2 == 0)
  30. n = n / 2;
  31. else
  32. n = (n*3 + 1) / 2;
  33. System.out.printf("%d ", n);
  34. }
  35. System.out.printf("\n");
  36. }
  37. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement