劉任昌w3schools遞迴函數recursive function

先利用w3schools再利用VS Code

public class Main {       //劉任昌2022.12.16類別名稱Main
  public static void main(String[] args)//必須存成Monkey.java
  { int r = 16;                    //宣告整數r=方法sum
    for (int i =0; i < r; i++) {  //迴圈
    System.out.print(i + "累加 "+ sum(i) );
    System.out.println(" 累乘機 "+ f(i) );}
  }
  public static int sum(int k) { //方法(函數sum)參數 k
    if (k > 0) {                 //條件判斷
      return k + sum(k - 1);  //k>0, 計算 k + sum(k-1)遞迴
    } else {                //遞迴,類似f(f(f(x)))函數
      return 0;
    }
  }
    public static int f(int k) { //方法(函數f)參數 k
    if (k > 0) {                 //條件判斷
      return k * f(k - 1);  //k>0, 計算 k * f(k-1)遞迴
    } else {                //遞迴,類似f(f(f(x)))函數
      return 1;
    }
  }
}

先利用w3schools

Visual Studio Code

劉任昌教學影片

留言

  1. https://cindy-javascript.blogspot.com/2022/12/blog-post.html

    回覆刪除
  2. https://d11150116.blogspot.com/2022/12/w3schoolsrecursive-function.html

    回覆刪除
  3. https://rtytrdtfg.blogspot.com/2022/12/w3shcoolsrecursive.html

    回覆刪除
  4. https://tgyhjikolujik2554.blogspot.com/2022/12/blog-post.html

    回覆刪除
  5. https://d11150115.blogspot.com/2022/12/w3schoolsrecursive-function.html

    回覆刪除
  6. https://www.blogger.com/blog/post/edit/5444106583314177344/6361724055201097258

    回覆刪除
  7. https://d11150112.blogspot.com/2022/12/blog-post_15.html

    回覆刪除
  8. https://643gjeytfru4312.blogspot.com/2022/12/w3schoolsrecursive-function.html

    回覆刪除
  9. https://iuytjhg5261.blogspot.com/2022/12/blog-post.html

    回覆刪除
  10. https://jdoifjopq1264.blogspot.com/2022/12/w3schoolrecursive-function.html

    回覆刪除
  11. https://d11150114.blogspot.com/2022/12/w3schoolsrecursive-function.html

    回覆刪除
  12. https://lihtml-css-javascript-java.blogspot.com/2022/12/w3schoolsrecursive-function.html

    回覆刪除
  13. https://chenyixun11117218.blogspot.com/2022/12/w3schoolsrecursionrecursion.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌對照Python與JavaScript指令

劉任昌Python集合set清單list元組tuple字典dictionary

劉任昌python, input, str, float