package pro1214test;
import java.util.Scanner;
public class eCiShu {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入一串字符");
String t = s.next();
System.out.println("请输入要查询次数的字符");
String t1=s.next();
String y = null;
String[] A = new String[t.length()];
for (int o = 0; o < t.length(); o++) {
A[o] = t.substring(o, o + 1);
//System.out.println(A[o]);
}
s(A, t1);
//System.out.println(s(A, t1));
int l=0;
if(A[0].equals(t1)) {
l++;
}if(A[A.length-1].equals(t1)) {
l++;
}
System.out.println("字符"+t1+"在"+t+"中出现的次数为"+(s(A, t1)+l));
}
static int s(String[]A,String t1) {
int count = 0;
for (int p = 0; p < A.length; p++) {
for (int q = 1; q < A.length - 1; q++) {
if (A[p] == (A[q]) && A[p].equals(t1+"")) {
// System.out.println("p的值为"+A[p]+",q的值为"+A[q]);
count++;
//System.out.println(count);
}
}
}return count;
}}
/*
* static int c(String[]ARR) { int count=0; for(int y=0;y<ARR.length-1;y++) {
* if(ARR[y].equals(ARR[y+1])) { count++; //break; } }
*
* return count;
*
*
*
* } } // System.out.println(t); // String[]ARR=t.split("e"); // int
* o=ARR.length;
*/
编写一个程序,实现从命令行参数输入一字符串,统计该字符串中字符输入字符的出现的次数。
最新推荐文章于 2021-12-04 22:04:53 发布