Advertisement
Guest User

Untitled

a guest
Nov 4th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. public class Hausaufgabe2 {
  3.  
  4.  
  5. public void aufgabe1() {
  6. int startwert = 0;
  7. int n = 0;
  8.  
  9. for (int i = 0; i < 999999; i++) {
  10. n = i;
  11. startwert = i;
  12. while (n > 0) {
  13. if (n == 4444) {
  14. System.out.println(startwert);
  15. break;
  16. }
  17. if (n % 2 == 0) {
  18. n = n / 2;
  19. } else {
  20. n = n * 3 + 1;
  21. }
  22. }
  23.  
  24. if (n == 4444) {
  25. break;
  26. }
  27. }
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34. public static void main(String[]args) {
  35. Hausaufgabe2 test = new Hausaufgabe2();
  36.  
  37. test.aufgabe1();
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement