- //程序功能:将大写字母变成小写,小写变成大写;
public class Example4_20
{
public static void main(String args[])
{
}int i; char a[]= {'a','b','c','D','E','F'}; //创建字符 for(i=0;i<a.length;i++); { if(Character.isLowerCase(a[i])) a[i]=Character.toUpperCase(a[i]); if(Character.isUpperCase(a[i])) //else a[i]=Character.toLowerCase(a[i]); } for (i=0;i<=a.length;i++) { System.out.println(" "+a[i]); }
}
运行结果及报错内容
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6
at Example4_20.main(Example4_20.java:10)
我想要达到的结果
将大写字母变成小写,小写变成大写;
编译通过,运行报错,不知道怎么改正。求指导