为什么这个程序运行时出现错误,但是我改了之后,就一切正常了,(红笔处):( 这还是书中的一个例题)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Bubble extends JApplet
{
public void init()
{
JTextArea outputArea = new JTextArea();
Container container = getContentPane();
container.add ( outputArea );
int array[] = {2,45,23,54,65,43,23,76,47,12,37,85,77};
String ouptut ="原数据顺序是:\";
for ( int i=0; i<array.length; i++ )
output += " " + array[i];
bubble ( array );
output +="\n\n 排序后的数据是:\n";
for ( int i=0; i<array.length; i++ )
output += " " + array[i];
outputArea.setText ( output );
}
public void Bubble ( int array2 )
{
for ( int i=0; i<array2.length; i++ )
{
for ( int j=0; j<array2.length; j++ )//改为:for (int j=i;j<array2.length;j++);
{
if ( array2[i]>array2[i+1]//改为if (array2[i]>array2[j];
swap ( array2,i,i+1 );//swap ( array2,i,j );
}
}
}
pbulic void swap ( array2[],first,second )
{
int hold ;
hold = array2[first];
array2[first] = array2[second];
array2[second] = hold ;
}
}