這裏是我的代碼到一個數組方法:如何簡化這個數組方法?
private int _a;
public static void main(String[] args) {}
public int[] countAll(String s) {
int[] xArray = new int[27];
int[] yArray = new int[27];
_a = (int)'a';
for (int i = 0; i < xArray.length; i++) {
xArray[i] = _a;
_a = _a++;
}
for (int j = 0; j < s.length(); j++) {
s = s.toLowerCase();
char c = s.charAt(j);
int g = (int) c;
int letterindex = g - yArray[0];
if (letterindex >= 0 && letterindex <= 25) {
xArray[letterindex]++;
} else if (letterindex < 0 || letterindex > 25) {
xArray[26]++;
}
}
return xArray;
}
此代碼Java編寫,但有人告訴我,有一個簡單的方法。我在計算我的代碼的簡化版本時遇到了很多麻煩。請幫幫我。
如果你告訴我們它會做什麼會有所幫助。 –
對於一件事'_a = _a ++;'與'_a ++相同;' –
另一件事,你是否需要在for循環中每次調用它:「s = s.toLowerCase();」 – mike01010