错误修正
import javax.swing.*;
public class test4{
public static void main(String args[]){
int a[] = new int [10];
for (int counter =0; counter<=a.length;counter++)
a[counter] = 2*counter;
String output ="INDEX\tVALUE\n";
for (int counter=0; counter<=a.length; counter++)
output += counter+"\t"+a[counter]+"\n";
JTextArea outputArea = new JTextArea();
outputArea.setText(output);
JOptionPane.showMessageDialog( null, outputArea,"shuzu",JOptionPane.INFORMATION_MESSAGE);
System.exit( 0 );
}
}
------解决方案--------------------
for循环里面应该是
counter < a.length
不然
数组越界!改了就好了