import java.util.Scanner;/*** 给出一句英文句子统计有多少个以某字母开头的单词* @author 佳哥**/public class TestChar {public static void main(String[] args) {char words;String str;Scanner sc = new Scanner(System.in);System.out.println("请输入字符串:");str = sc.nextLine();System.out.println("请输入开头的字母:");words = sc.next().charAt(0);System.out.println(str);int count = 0;String[] strArray = str.split(" ");//把字符串通过" "(空格)拆分为字符串数组for (int i = 0; i < strArray.length; i++) {if(strArray[i].charAt(0) == words) {count++;}}System.out.println(count);}}
本文发布于:2024-02-01 04:46:08,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170673397033961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |