返回列表 發帖
  1. public class CH01 {
  2.     static int totle(int x)
  3.     {
  4.         if(x==1)
  5.                 return 1;
  6.         else
  7.                 return x+totle(x-1);
  8.     }      
  9.     public static void main(String[] args)
  10.     {
  11.         System.out.println("1+2+.....+5="+totle(5));
  12.         System.out.println("1+2+.....+101="+totle(101));
  13.         System.out.println("1+2+.....+257="+totle(257));   
  14.     }
  15. }
複製代碼

TOP

返回列表