import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String string = "H e l l o ! n o w c o d e r";
Scanner scanner= new Scanner(System.in);
String word = scanner.next();
scanner.close();
System.out.println(check(string, word));
}
public static int check(String str,String word){
return str.length() - str.replace(word,"").length();
}
}
// import java.util.Scanner;
// public class Main {
// public static void main(String[] args) {
// String string = "H e l l o ! n o w c o d e r";
// Scanner scanner= new Scanner(System.in);
// String word = scanner.next();
// scanner.close();
// System.out.println(check(string, word));
// }
// public static int check(String str, String word) {
// //write your code here......
// int n =0;
// int i = 0;
// while(i < str.length())
// {
// if(str.indexOf(word, i) != -1)
// {
// n++;
// i = str.indexOf(word,i)+1;
// }
// else
// {
// break;
// }
// }
// return n;
// }
// }
str.replace()你学会了么
替换之后求长度变化



京公网安备 11010502036488号