私は単純な再帰的な Java ファイルを持っています。コードは次のとおりです
public class Rekursion_SA_UE {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
count(1, 10);
}
public static int count(int zahl, int max)
{
if(zahl>max) return zahl;
else{
System.out.println(zahl);
count(zahl+1, max);
return zahl;
}
}
出力は 1,2,3,4,5,6,7,8,9,10 です。2 行を切り替えると、10 から下に向かってカウントされます。のように見えます
public class Rekursion_SA_UE {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
count(1, 10);
}
public static int count(int zahl, int max)
{
if(zahl>max) return zahl;
else{
count(zahl+1, max);//switched
System.out.println(zahl);//switched
return zahl;
}
}
ここでの出力は 10,9,8,7,6,5,4,3,2,1 です。何故ですか?前もって感謝します。