任何人都可以請解釋遞歸循環的打印順序嗎?解釋遞歸循環的打印輸出順序?
import java.util.Scanner;
public class DecimalToBinary {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int decimalNum;
int base;
base = 2;
System.out.println("Enter a nonnegative integer in decimal: ");
decimalNum = console.nextInt();
System.out.println();
System.out.println("Decimal " + decimalNum + " = ");
decToBin(decimalNum, base);
System.out.println(" binary");
}
public static void decToBin(int num, int base) {
if (num == 0) {
System.out.print(0);
} else if (num > 0) {
decToBin(num/base, base);
System.out.print(num % base);
}
}
}
Num % base
必須打印相反的順序是這樣的:
爲什麼如圖所示調用的順序? (請幫我修改我的問題,英文是我的外語)