返回列表 發帖
  1. package hi87;

  2. import java.util.Scanner;

  3. public class hi788 {
  4.     static Scanner keyboard = new Scanner(System.in);
  5.     public static void main(String args[]) {
  6.         
  7.                
  8.      System.out.print("Input m:");
  9.      int m=keyboard.nextInt();
  10.      System.out.print(f(m));
  11.      }          

  12.    
  13.    
  14.     static int f(int m)
  15.     {
  16.            
  17.             if(m==1)
  18.             {
  19.                     return 2;
  20.             }
  21.             else
  22.             {
  23.                     return f(m-1)+2*m;
  24.             }
  25.     }
  26. }
複製代碼

TOP

返回列表