标签:main i++ print div 大小 character line int color
package lsh.element.algrithom; import java.util.Scanner; public class CountLetterIgnoreCase { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入带有字母的字符串: "); String str = input.nextLine(); int[] countLetters = countLetters(str.toLowerCase()); for (int i = 0; i < countLetters.length; i++) { System.out.println((char)(‘a‘+i)+" 出现了 "+countLetters[i]+" 次;"); } input.close(); } /** * 巧妙地利用了被处理对象内部的结构关系 * @param str * @return */ public static int[] countLetters(String str) { int[] counts = new int[26]; for (char e : str.toCharArray()) { if(Character.isLetter(e)) { counts[e - ‘a‘]++; } } return counts; } }
标签:main i++ print div 大小 character line int color
原文地址:https://www.cnblogs.com/InformationGod/p/9693463.html