Java输入一个数字字符串,输入一个数,判断重复数字有几个?
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
int a = scanner.nextInt();
int count = 0;
for(int i=0;i<str.length();i++){
if(str.charAt(i) - '0' == a){
count++;
}
}
System.out.println(count);
}
}
String test ="123134123413213";
char a = "1";
int strLength = test.length;
int repLength = test.replaceAll(test,a);
int result = strLength -repLength ;
可以举个例子不,是个位数上出现重复吗,例如“123abc124”,算不算出现重复
不太理解题意,因为有歧义,比如222,会不会输入数字是22?22的话,算不算重叠部分?算重复1次还是2次?