Scanner sc = new Scanner(System.in);
System.out.println("Please enter a string and a character following the string(use a space to split them)");
String input = sc.nextLine();
String str = input.substring(0, input.lastIndexOf(" "));
String ch = input.substring(input.lastIndexOf(" ") + 1);
int occuredTimes = str.splits(ch).lenght - 1;
occuredTimes = occuredTimes < 0 ? 0 : occuredTimes ;
System.out.println(ch + " occurs " + occuredTimes + " times in " + str);
sc.close();
追问高手啊,不过真心看不懂==