首页 > 学院 > 开发设计 > 正文

写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写.

2019-11-08 03:12:16
字体:
来源:转载
供稿:网友
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);    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表