返回列表 發帖
  1. package hi87;

  2. import java.util.Scanner;

  3. public class hi78 {
  4.          static Scanner keyboard = new Scanner(System.in);
  5.         public static void main(String[] args) {
  6.                 // TODO 自動產生的方法 Stub
  7.                         String s, c;
  8.                         System.out.print("Input a string: ");
  9.                         s = keyboard.nextLine();
  10.                         System.out.printf("%s\n", reserve(s));
  11.                         
  12.                     }
  13.                     
  14.                     static String reserve( String str)
  15.                     {
  16.                             if(str.equals(""))
  17.                             {
  18.                                     return "";
  19.                             }
  20.                             else{
  21.                                     return reserve(str.substring(1))+str.substring(0,1);       
  22.                             }
  23.                            
  24.                        
  25.                     }
  26.                 }
複製代碼

TOP

返回列表