返回列表 發帖
  1. package text;
  2. import java.util.Scanner;
  3. public class JPA04 {
  4.     static Scanner keyboard = new Scanner(System.in);
  5.     public static void main(String args[]) {
  6.         String s, c;
  7.         System.out.print("Input a string: ");
  8.         s = keyboard.nextLine();
  9.         System.out.print("Input a character: ");
  10.         c = keyboard.nextLine();
  11.         System.out.printf("%s\n", removeChar(s, c));

  12.     }
  13.     static String removeChar(String n,String m)
  14.     {
  15.             if(n.equals(""))
  16.             {
  17.                     return "";
  18.             }
  19.             else if(n.substring(0,1).equals(m))
  20.             {
  21.                     return removeChar(n.substring(1),m);
  22.             }
  23.             else{
  24.                     return n.substring(0,1)+removeChar(n.substring(1),m);
  25.             }
  26.     }
  27.    
  28. }
複製代碼

TOP

返回列表