Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 11

前端 未结 4 1594
别那么骄傲
别那么骄傲 2020-12-16 06:54

EVerytime I write any code similar to this one, I get this type of error. It\'s building a file but not letting it run, it just throws exception. I\'m not familiar with exce

4条回答
  •  太阳男子
    2020-12-16 07:06

    try this:

    public static void main(String args[]) {
    String name = "Umer Hassan";
    String name1 = "Hassan Umer";
    char[] name2 = new char[name.length()];
    
    for (int j = 0; j < name.length(); j++ {
        for (int i = 0; i < name.length(); i++) {
            if (name.length() == name1.length()) {
                if (name.charAt(i) == name1.charAt(j)) {
                    name2[i] = name1.charAt(j);
                }
            }
        }
    }
    

    }

提交回复
热议问题