Ich muss folgende Aufgabe möglichst gut und ordentlich lösen:
http://jeebone.je.funpic.de/java/3.JPG
das hab ich bisher folgendermaßen gemacht:
public static void main(String[] args)
{
int[] result = collatzRec2(6);
System.out.print("r: " + result[0] + ", " + result[1]);
}
public static int[] collatzRec2(int n, int len, int max)
{
if(n == 1)
return new int[] {1, 1};
if(n % 2 == 0)
n /= 2;
else
n = 3 * n + 1;
len++;
max = Math.max(max, n);
int[] i = {len, max};
if(n != 1)
i = collatzRec2(n, len, max);
return i;
}
public static int[] collatzRec2(int n)
{
return collatzRec2(n, 0, 0);
}
}```
da ich aber noch Anfänger bin, wird das sicher nicht perfekt sein, könntet ihr mir sagen, wo da noch was zu verbessern ist, bzw wo was nicht so schön ist usw ...