统计字符串的每个字母-创新互联
impo
public class Zhouhai {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入一字符串:");
String a = input.nextLine();
shaoshao(a.toLowerCase());
}
public static void shaoshao(String a) {
int[] number = new int[26];
for(int i = 0; i < a.length(); i++)
number[a.charAt(i) - 'a'] ++;
for(int i = 0; i < number.length; i++)
if(number[i] != 0)
System.out.println((char)('a'+i)+"出现的次数:"+number[i]);
}
}
当前标题:统计字符串的每个字母-创新互联
本文来源:http://myzitong.com/article/dppjhs.html
public class Zhouhai {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入一字符串:");
String a = input.nextLine();
shaoshao(a.toLowerCase());
}
public static void shaoshao(String a) {
int[] number = new int[26];
for(int i = 0; i < a.length(); i++)
number[a.charAt(i) - 'a'] ++;
for(int i = 0; i < number.length; i++)
if(number[i] != 0)
System.out.println((char)('a'+i)+"出现的次数:"+number[i]);
}
}
![统计字符串的每个字母
统计字符串的每个字母](/upload/otherpic26/2134632.jpg)
当前标题:统计字符串的每个字母-创新互联
本文来源:http://myzitong.com/article/dppjhs.html