返回列表 發帖
  1. public class Ch241 {
  2.     static int tot(int g)
  3.     {
  4.             if(g==1)
  5.                     return 1;
  6.             else
  7.                     return g+tot(g-1);
  8.     }
  9.         public static void main(String[] args) {
  10.                 System.out.println("1+2+3+...+5="+tot(5));
  11.                 System.out.println("1+2+3+...+101="+tot(101));
  12.                 System.out.println("1+2+3+...+257="+tot(257));
  13.         }

  14. }
複製代碼

TOP

返回列表