Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can somebody help me with a sorting program? Posted by sniper316 on 13 Feb 2005 at 6:34 PM
This program needs to take an array and sort the numbers inside the array from least to greatest. Use BubbleSort. There are six numbers in the array. Can somebody help me with the code???
Report
Re: Can somebody help me with a sorting program? Posted by Vilanye on 13 Feb 2005 at 7:02 PM
: This program needs to take an array and sort the numbers inside the array from least to greatest. Use BubbleSort. There are six numbers in the array. Can somebody help me with the code???
:


Where are you stuck at?

The size of the array is irrelevant, that information can be retrieved at runtime, so if you write it correctly it will work for any size array.
Report
Re: Can somebody help me with a sorting program? Posted by sniper316 on 13 Feb 2005 at 7:57 PM
Could you write the code for me then?
Report
Re: Can somebody help me with a sorting program? Posted by sfkwan on 14 Feb 2005 at 5:55 AM
: Could you write the code for me then?
:


public class sorting
{
public static void main(String [] args)
{
int [] data = {5,2,6,4,1,3};
int temp;


for(int j=1; j<data.length;j++)
{
for(int i=1; i<data.length;i++)
if(data[i-1] > data[i])
{
temp = data[i-1];
data[i-1] = data[i];
data[i] = temp;
}
for(int k=0;k<data.length;k++)
System.out.print(data[k]+" ");
System.out.println();
}

}
}
Report
Re: Can somebody help me with a sorting program? Posted by sniper316 on 14 Feb 2005 at 5:58 PM
Thanks Sfkwan! I appreciate it. By looking through the code I can better interpret how it works.
Report
Re: Can somebody help me with a sorting program? Posted by Vilanye on 14 Feb 2005 at 8:56 AM
: Could you write the code for me then?
:

No I won't and sfkwan shouldn't have. You don't learn anything by having others write code for you.
Report
Re: Can somebody help me with a sorting program? Posted by sfkwan on 14 Feb 2005 at 10:33 PM
: : Could you write the code for me then?
: :
:
: No I won't and sfkwan shouldn't have. You don't learn anything by having others write code for you.
:

what Vilanye said is right. I shouldn't write the full code.
But, I think these is the best way to help them who are not familiar to Java Language.
Thanks a lot to Vilanye.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.