早教吧 育儿知识 作业答案 考试题库 百科 知识分享

java计算字母的出现次数WriteaJavaprogramcalledCharacterCount.javathatpromptstheusertoenteraString.TheprogramwillthendisplaythenumberofcharactersintheStringandthenprompttheusertoenterasinglecharacter(check

题目详情
java 计算字母的出现次数
Write a Java program called CharacterCount.java that prompts the user to enter a String. The program will then display the number of characters in the String and then prompt the user to enter a single character (check slides). It will then iterate along the String and count the occurrences of that character (Note: Upper and Lowercase characters must be counted together, spaces and punctuation marks are also characters). The output must match the layout below (The user inputs may differ).
Sample of the program output.
$> Enter a String: She sells sea shells
Number of characters: 20
Enter a character: s
The character 's' occurs 6 times.
▼优质解答
答案和解析
import java.util.*;
public class A
{
public static void main(String[] args)
{
int count=0;
String s="kasdkadada";
String[] str=new String[s.length()];
for(int i=0;i