This isn't a "we do your homework" service!
Try to answer it yourself. Post your best answer here. Based on that people will give you the help you need.
DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
You're 95% of the way there...
Add some temporary print statements inside your loops etc so you can see what the values of the variables are as the program executes. That will help you find exactly where it's going wrong.
JamesCherrill
... trying to help
8,519 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,455
Skill Endorsements: 30
I think you need "bubble-sort" algorithm for ascending order sort.
Only thing is your sort() function is incorrect.
Below is the modified code for
public void sort() {
int x=a.length;
for(int i=0 ; i< x;i++){
for(int k=i+1;k<x; k++)
{
if(a[i] > a[k]){
swap(i, k);
}
}
}
}
output of the sample run of above code
5 7 3 6 9
3 5 6 7 9
subramanya.vl
Junior Poster in Training
81 posts since Oct 2012
Reputation Points: 0
Solved Threads: 10
Skill Endorsements: 1