導入Java . util . regex . pattern;
公共類EasyTest {
公共靜態void main(String[] args) {
int num = 0;
掃描儀掃描;
System.out.println("請輸入壹個字符串");
scan =新掃描儀(system . in);
string s 1 = scan . nextline();
System.out.println("請輸入壹個字符");
string S2 = scan . next line();
if(Pattern.matches(" . ",s2)){
char[]a 1 = s 1 . tochararray();
char[]a2 = S2 . tochararray();
for(int I = 0;我& lts 1 . length();i++){
if(a1[i]==a2[0])
num++;
}
system . out . println(num);
}
其他
System.out.println("您的輸入有誤!!!");
}
}
從控制臺輸入,經測試完全符合要求。對於窗口輸入,您還可以。
大家* * *有進步!!!