
I am trying the run this code also in eclipse, but there seem to be some nuances. Can yo please check and run this source code and let me know why is it was not running?
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

Here is an example that sorts the array of numbers from smallest to largest.
class SortArray
{
public static void main(String[] args) {
int array[] = {15,2,70,35,60,21,47,56};
int temp=0;
for(int i=0;i<array.length;i++)
{
for(int j=array.length-1;j>i;j--)
{
if(array[i]>array[j]){
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
for(int i=0;i<array.length;i++)
System.out.println(array[i]);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.