Why would you not use the facilities offered in the standard JCL? Are you doing this as an exercise for a programming class, or are you coding something for a real-world project?
If it's for a project and you want to get the job done with a minimum of effort and a maximum of quality, look into the java.util.Arrays class, which has various overloaded sort methods. If sorting Objects, you'll want to have them implement the java.util.Comparator interface in order to define the sorting order.
Yes, I am trying this code for a problem given to me in an assignment. I hav succeeded a bit in cracking the logic of sorting members in ascending order. Here it is :
class SortArray
{
public static void main(String args[])
{
int arr1[] = {11,15,8,9,3,6,10,12,5,1,2,13,4,7,14};
for (int i=0;i<arr1.length;i++) System.out.println(arr1[i]);
for(int i=0;i<(arr1.length-1);i++)
{
for (int j=i+1;j<arr1.length;j++)
{
if(arr1[i]>arr1[j])
{
int x,y;
x=arr1[i];
y=arr1[j];
arr1[i] = y;
arr1[j] = x;
}
}
}
System.out.println("Array after sorting in ascending order");
System.out.println();
for (int i=0;i<arr1.length;i++) System.out.println(arr1[i]);
}
}
This wrks fine iff array members are initialised inadvance. I want this prgm to be like : an object of class SortArray will invoke diff methods to initialize size of array, random assignment of its members and then arranging them in ascending order.
class SortArray
{
public static void main(String args[])
{
int arr1[] = {11,15,8,9,3,6,10,12,5,1,2,13,4,7,14};
for (int i=0;i<arr1.length;i++) System.out.println(arr1[i]);
for(int i=0;i<(arr1.length-1);i++)
{
for (int j=i+1;j<arr1.length;j++)
{
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.