Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Java program for bubble sort

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java program for bubble sort

    Please tell is this the right code for BUBBLE SORT...
    it sorts the array but does it apply the logic of BUBBLE SORT????


    public class sortx
    {
    	public static void main(String args[])
    	{
    	int num[]={ 4,15,3,8,5,7,2,0,33,22};
    	for(int i=0;i<9;i++)
    	{
    		for(int j=i+1;j<10;j++)
    		{
    		if(num[i]>num[j])
    		{
    		int temp =num[i];
    		num[i]=num[j];
    		num[j]=temp;
    		}
    		}
     
    	}
    	for(int l=0;l<10;l++)
    		System.out.println(num[l]);
    	}
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java program for bubble sort

    Please read the link in my signature on asking questions the smart way, then try again.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java program for bubble sort

    I am a new user and i could not find which signature link u r asking me to read..

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Java program for bubble sort

    Recommended reading: How To Ask Questions The Smart Way

    Specifically, you haven't really asked a question, you've just posted some code. What does this code do? What do you expect it to do? What happened when you stepped through this with a debugger or added some print statements? When does the execution of the program differ from what you expect?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java program for bubble sort

    Quote Originally Posted by shvn2693 View Post
    Please tell is this the right code for BUBBLE SORT...
    it sorts the array but does it apply the logic of BUBBLE SORT????
    What is bubble sort? ...in terms of the logic?
    How does bubble sort work? List the steps that are taken in bubble sort.

    What does this code do?
    Take some samples and sort them manually by stepping through the code.
    Are these steps the same as bubble sort?

    Ask any questions you have after poking around with it

Similar Threads

  1. Bubble Sort Help
    By asundar in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 24th, 2012, 05:14 PM
  2. bubble sort timer
    By gujinni in forum Other Programming Languages
    Replies: 1
    Last Post: October 15th, 2011, 09:30 AM
  3. Bubble Sort help
    By baueml01 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 5th, 2011, 08:47 PM
  4. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM
  5. Javascript Bubble Sort
    By Fidelacchius in forum What's Wrong With My Code?
    Replies: 17
    Last Post: May 24th, 2010, 04:43 PM