import java.io.*;
import java.util.Scanner;
public class ws1qn2
{
public static void main(String[] args) throws IOException
{
Scanner input=new Scanner(System.in);
int a;
int d;
System.out.println("Please enter the number of characters the word has: ");
d=input.nextInt();
a=d-1;
char word[]=new char[a];
for (int b=0;b!=a;b++)
{
System.out.println("Please enter character no."+b+1);
String str;
str=input.next();
char c=str.charAt(b);
word[a-b]=c;
}
for (char reverse : word)
{
System.out.print(reverse);
}
}
}
這是當我運行該程序會發生什麼:ArrayIndexOutOfBoundsException異常在Java
Please enter the number of characters the word has:
3
Please enter character no.01
s
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at ws1qn2.main(ws1qn2.java:22)
Process completed.
幫助?它看起來像一個堆棧溢出,但我不知道如何解決它。
看起來像一個'ArrayIndexOutOfBoundsException'給我... –
是的..我想知道這是如何堆棧溢出.. –