
I am trying the run this code also in eclipse, but there seem to be some nuances. Can you please check and run this source code and let me know why is it was not running? Can you please send me this source code after it is working. This source code is the answer, but there might be some glitches. Can you please fix them and then send me the version that works.
Instruction: Write a Java program that contains an array of numbers which is then sorted from smallest to largest.
Code:
import java.applet.Applet; import java.awt.*;
public class sortingnumbers extends Applet
{
int data [] = {45,89,2,6,100,99,23,56,78,1,32,44,33,11};
// data array public void paint (Graphics g) { sorting ();
// initially empty print (g, "Sorted numbers:", data, 20, 30);
// send output to screen } public void sorting () {
// begin sorting method int inprocess; for (int a = data.length - 2;
a >= 0; a --) for (int b = 0;
b <= a ; b ++) if (data [b] > data [b+1] ) {
// transpose the numbers inprocess = data[b];
data[b] = data[b+1]; data[b+1] = inprocess;
} // end transposing of numbers }
// end sorting method public void print
// format output (Graphics g, String v, int w[], int x, int y)
{g.drawString (v, x, y); x += 15;
y += 15; for (int a = 0;
a <= w.length - 1; a++)
{
g.drawString (String.valueOf(w[a]),x,y);
x += 25;
}
// for
}
// end method
}
// class sortingnumbers