关于数组越界问题
程序代码:
package countletter; import java.util.Scanner; public class Countletter { public static void main(String args[]) { Scanner in = new Scanner(System.in); String str = in.nextLine(); str=str.toLowerCase(); int[] a = new int[26]; for(int i = 0;i < str.length();i++) { char c = str.charAt(i); int index = c - 'a'; a[index] = a[index] + 1; } for(int i = 0;i < a.length;i++) { if(a[i]!=0) { System.out.println("("+(char)(i+'A')+")"+"Num="+a[i]); } } } }