寫出一個程序,接受一個有字母和數字以及空格組成的字符串,和一個字符,然後輸出輸入字符串中含有該字符的個數。不區分大小寫.

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        find(str1,str2);
        
    }
    
    public static void find(String s1,String s2){
        int count = 0;
        s1 = s1.toLowerCase();
        byte[] temp = s1.getBytes();
        for(int i =0;i<temp.length;i++){
            if(temp[i] == s2.toLowerCase().charAt(0)){
                count++;
            }
        }
        
       System.out.println(count);
    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章