package com.llh.demo; import java.util.Scanner; /**
*
* @author llh
*
*/
public class Test {
/*
* 在某个字符数组中查找某个字符出现的次数
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符:");
char a = sc.next().charAt(0);
int count = 0;
boolean b = true;
char[] letter = { 'a', 'b', 'c', 'd', 'c' };
for (int i = 0; i < letter.length; i++) {
if (a == letter[i]) {
count++;
b = false;
}
}
if (b == false) {
System.out.println("这个字符在字符数组中出现过" + count + "次!");
} else {
System.out.println("这个字符不在字符数组中!");
} } }