package lianxi;class Wheel{
public static void main(String[] args){
String phrase[]={
"A STITCH IN TIME SAVES NINE",
"DON'T EAT YELLOW SNOW",
"JUST DO IT",
"EVERY GOOD BOY DOES FINE",
"I WANT MY MTV",
"I LIKE IKE",
"PLAY IT AGAIN, SAM",
"FROSTY THE SNOWMAN",
"ONE MORE FOR THE ROAD",
"HOME FIELD ADVANTAGE",
"VALENTINE'S DAY MASSACRE",
"GROVER GLEVELAND OHIO",
"SPAGHETTI WESTERN",
"AQUA TEEN HUNGER LIFE"
};
int[] letterCount = new int[26];
for(int count=0;count<phrase.length;count++){
String current=phrase[count];
char[] letters=current.toCharArray();
for(int count2=0;count2<letters.length;count++){
char lett=letters[count2];
if((lett>='A') & (lett<='Z')){
letterCount[lett-'A']++;
}
}
}
for(char count='A';count<='Z';count++){
System.out.print(count+":"+letterCount[count-'A']+" ");
}
System.out.print('\n');
}
}这个代码是利用NetBeans来编译的,主项目是Lianxi,但是为什么编译器老是运行不了呢?没有报错,只是一直在运行中。
public static void main(String[] args){
String phrase[]={
"A STITCH IN TIME SAVES NINE",
"DON'T EAT YELLOW SNOW",
"JUST DO IT",
"EVERY GOOD BOY DOES FINE",
"I WANT MY MTV",
"I LIKE IKE",
"PLAY IT AGAIN, SAM",
"FROSTY THE SNOWMAN",
"ONE MORE FOR THE ROAD",
"HOME FIELD ADVANTAGE",
"VALENTINE'S DAY MASSACRE",
"GROVER GLEVELAND OHIO",
"SPAGHETTI WESTERN",
"AQUA TEEN HUNGER LIFE"
};
int[] letterCount = new int[26];
for(int count=0;count<phrase.length;count++){
String current=phrase[count];
char[] letters=current.toCharArray();
for(int count2=0;count2<letters.length;count++){
char lett=letters[count2];
if((lett>='A') & (lett<='Z')){
letterCount[lett-'A']++;
}
}
}
for(char count='A';count<='Z';count++){
System.out.print(count+":"+letterCount[count-'A']+" ");
}
System.out.print('\n');
}
}这个代码是利用NetBeans来编译的,主项目是Lianxi,但是为什么编译器老是运行不了呢?没有报错,只是一直在运行中。
写成count去了,改为count2就ok了,复制的时候仔细点