public class_AbcdCount{
/*为了弄清某类考试中,选择题答案abcd的分布情况,需要统计abcd出现的次数。
现从键盘输入一行由abcd构成的答案字符串,统计并输出abcd出现的次数。(如果未出现,则次数输出0)
*/
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//输入提示
Scanner sc=new Scanner(System.in);
System.out.print("请输入:");
String str=sc.next();
System.out.println(str);
//建立两个数组 一个int类型 一个String字符串类型
int a=0;
int b=0;
int c=0;
int d=0;
int daan[] = {a,b,c,d}; //定义一个长度4的整型数组
String da = "";
for(int i=0;i<daan.length;i++){
str = str + daan[i]; //拼接成字符串,最终放在变量str中
// 定义变量length用来存放输入字符串的长度
char[]chs=str.toCharArray();
//for循环String数组判断abcd出现的次数
for (int daan = 0; i<chs.length; i++){
if(str[i] != null)
System.out.println(+char[i]+count[i]);
}
// 统计a出现的次数
if (str[i] == 'a') {
a++;
}
// 统计b出现的次数
else if (str[i] == 'b'){
b++;
}
// 统计c出现的次数
else if (str[i] == 'c'){
c++;
}
// 统计d出现的次数
else if (str[i] == 'd'){
d++;
}
}
//输出结果
System.out.println(a, b, c, d);
}//main
}
【作为 一个渣渣我已经深刻认识到不认真听课的下场,
好多错误,有很多就是,比如定义之类的东西都弄不清,求救求救~~救救这个没头没脑的代码吧,怪可怜的~~~~~~··】
|
|