Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/40ba46bca67d93c041e68d33f67f7b00 to your computer and use it in GitHub Desktop.
Save peter279k/40ba46bca67d93c041e68d33f67f7b00 to your computer and use it in GitHub Desktop.
TQC+ JAVA
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Input a string: ");
String str = keyboard.nextLine();
System.out.print("Input a character: ");
String chr = keyboard.nextLine();
System.out.println(strDel(str, chr));
System.out.print("Input a string: ");
str = keyboard.nextLine();
System.out.print("Input a character: ");
chr = keyboard.nextLine();
System.out.println(strDel(str, chr));
}
public static String strDel(String str, String chr) {
if(str.equals("")) {
return "";
}
if(str.substring(0, 1).equals(chr)) {
return "" + strDel(str.substring(1), chr);
}
return str.substring(0, 1) + strDel(str.substring(1), chr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment