日期:2014-05-20  浏览次数:20847 次

错误修正
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
  不然数组越界!改了就好了