import java.util.Scanner;
public class StringDemo {
static char[] cs = {'a','e','i','o','u'};
static char[] bcs = {'A','E','I','O','U'};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int[] arys = findChar(str);
for (int i = 0; iSystem.out.println(cs[i]+"出现的个数"+arys[i]);
}
System.out.println("大写元音字母的个数"+arys[5]);
System.out.println("非元音字母的个数"+arys[6]);
}
private static int[] findChar(String str) {
int[] arys = new int[7];//0~5存储每个小写元音的个数,6存储大写元音的个数,7存储非元音的个数
int sumx= 0;//用于保存元音字母的个数(不区分大小写)
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
for (int j = 0; j < cs.length; j++) {
if(c==cs[j]){
arys[j]++;//小写元音个数增加
sumx++;
break;
}
}
for (int j = 0; j < bcs.length; j++) {
if(c==bcs[j]){
arys[5]++;
sumx++;
break;
}
}
}
arys[6] = str.length()-sumx;//非元音的个数
return arys;
}
}
输出
AppleIlove
a出现的个数0
e出现的个数2
i出现的个数0
o出现的个数1
u出现的个数0
大写元音字母的个数2
非元音字母的个数5
import java.util.*;
public class Yugi {
public static void main(String[] args) {
Scanner scan = new Scanner(System. in );
String line = scan.nextLine().trim();
scan.close();
HashMap < Character, Integer > map = new HashMap < Character, Integer > ();
for (int i = 0; i < line.length(); i++) {
char c = line.charAt(i);
if (c >= 'a' && c <= 'z') {
if (null == map.get(c)) {
map.put(c, 1);
} else {
map.put(c, map.get(c) + 1);
}
}
}
System.out.println(map);
}
}
你是B班的。