小编Box*_*ras的帖子

数组索引超出范围异常(Java)

这是我的代码:

public class countChar {

    public static void main(String[] args) {
        int i;
        String userInput = new String();

        userInput = Input.getString("Please enter a sentence");

        int[] total = totalChars(userInput.toLowerCase());

        for (i = 0; i < total.length; i++);
        {
            if (total[i] != 0) {
                System.out.println("Letter" + (char) ('a' + i) + " count =" + total[i]);
            }
        }
    }

    public static int[] totalChars(String userInput) {
        int[] total = new int[26];
        int i;
        for (i = 0; i < userInput.length(); i++) {
            if …
Run Code Online (Sandbox Code Playgroud)

java arrays runtime-error

6
推荐指数
2
解决办法
11万
查看次数

标签 统计

arrays ×1

java ×1

runtime-error ×1