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("這個字符不在字符數組中!"); } } }