作者:潇然free | 来源:互联网 | 2024-09-30 10:59
[求助]无法从静态上下文中引用非静态方法小错能自己改就是LetterFrequencyDetector.java:53:无法从静态上下文中引用非静态方法buildAlphabet(
[求助]无法从静态上下文中引用非静态方法
小错能自己改 就是
LetterFrequencyDetector.java:53: 无法从静态上下文中引用非静态 方法 buildAlphabet
()
buildAlphabet( );
^
LetterFrequencyDetector.java:54: 无法从静态上下文中引用非静态 方法 removeNonLett
ers(java.lang.String)
ArrayList a=removeNonLetters(args[0]);
^
LetterFrequencyDetector.java:55: 无法从静态上下文中引用非静态 方法 calculateFreq
uencies(java.util.ArrayList)
calculateFrequencies(a);
^
LetterFrequencyDetector.java:56: 无法从静态上下文中引用非静态 方法 displayFreque
ncies()
displayFrequencies();
实在不知道怎么改了..
代码:
import java.util.*;
public class LetterFrequencyDetector{
ArrayList Alphabet = new ArrayList( );
ArrayList reAlphabet=new ArrayList( );
ArrayList Frequency=new ArrayList();
int[] count=new int[26];
public ArrayList buildAlphabet( ){
for(int i=97;i<=122;i++){
Alphabet.add((char)i);
}
return Alphabet;
}
public ArrayList removeNonLetters(String s){
s=s.toLowerCase();
for(int i=0;i
int c=s.charAt(i);
if(c>=97&&c<=122)
count[c-97]++;
}
for(int j=0;j<26;j++){
if(count[j]==0)
reAlphabet.remove(j);
}
return reAlphabet;
}
public ArrayList calculateFrequencies(ArrayList a){
Frequency.size=reAlphabet.size;
for(int i=0;i<26;i++){
if(count[i]!=0)
Frequency.add(count[i]);
}
return Frequency;
}
public void displayFrequencies(){
for(int i=0;i
System.out.print(reAlphabet.get(i)+"--"+Frequency.get(i));
for(int j=0;j
System.out.print("*");
}
System.out.println();
}
}
public static void main(String args[]){
buildAlphabet( );
ArrayList a=removeNonLetters(args[0]);
calculateFrequencies(a);
displayFrequencies();
}
}