• 07-21-2009, 10:23 AM
amalina
i got an assignment to do..
the assignment is:
write a program about sorting a negative to positive number in easy word from small to big number..
the original number given is:23 45 -234 -456 -2 -4 333 56 35
the sorted number is:-456 -234 -4 -2 23 35 45 56 333
thank you..
reply me as soon as possible..
• 07-21-2009, 11:30 AM
dswastik
I think you should try to do it yourself first. If you face problem we are always here to help you.
• 07-21-2009, 03:01 PM
amalina
i have tried to do by myself..
now there no much time left..
i have no idea what to do anymore..
its have come to the end of my critical thinking..
i cannot find any solution anymore..
could somebody help me out of this problem..
plz..
i need ur help..
a.s.a.p
:(
• 07-21-2009, 03:40 PM
dswastik
Code:

int nums[]={23,45,-234,-456,-2,-4,333,56,35};
for (int i = 0; i < nums.length - 1; i++){
for (int j = i + 1; j < nums.length; j++){
if (nums[i] > nums[j]){
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}

• 07-21-2009, 03:56 PM
amalina
i like to have in detail syntax..
the output have to be like this:
original number:23 45 -234 -456 -2 -4 333 56 35
sorted number:-456 -234 -4 -2 23 35 45 56 333
and the problem with your code is..
i didn't see any output..
but its stated build successful..
with none of the output i wanna see..
i really appreciate ur help...
• 07-21-2009, 03:59 PM
dswastik
Code:

int nums[]={23,45,-234,-456,-2,-4,333,56,35};
for (int i = 0; i < nums.length - 1; i++){
for (int j = i + 1; j < nums.length; j++){
if (nums[i] > nums[j]){
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
//you just need to print the array after sorting
for (int i = 0; i < nums.length; i++){
System.out.print(nums[x]+" ");
}

• 07-21-2009, 04:08 PM
amalina
i didnt not understand it well..
i said i want the output like i show u before..
it must have display the original and the sorted number...
its mean there is two line of output...
is ur code is readable by netbeans software...
i am so sorry..
very2 sorry..
• 07-21-2009, 04:17 PM
dswastik
Code:

public static void main(String[] arg){
int nums[]={23,45,-234,-456,-2,-4,333,56,35};

int unsortedNums[]=new int[nums.length];

//store the original numbers in the array called unsortedNums for displaying later
for(int x=0;x<nums.length;x++){
unsortedNums[x]=nums[x];
}

//sort the nums array
for (int i = 0; i < nums.length - 1; i++){
for (int j = i + 1; j < nums.length; j++){
if (nums[i] > nums[j]){
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
//display the original array i.e. array called unsortedNums
System.out.print("Original Numbers:");
for(int x=0;x<unsortedNums.length;x++){
System.out.print(unsortedNums[x]+" ");
}

//display the sorted array i.e. array called nums
System.out.print("\nSorted Numbers:");
for(int x=0;x<nums.length;x++){
System.out.print(nums[x]+" ");
}

//just to print a blank line
System.out.println("");
}

• 07-21-2009, 05:18 PM
amalina
tq damn much...
i cannot solve the problem...
thank you...
very2..
much...
i hope you can help me with the..
upcoming problem..
thank you....
• 07-21-2009, 06:15 PM
angryboy
hmmm... nice spoonfeeding session going on...
• 07-22-2009, 10:51 AM
Tolls
Oh joy. Someone else I'll have to clean up after in a few years time.