Elite Coders Society
Hello Guest!
Join us here in this forum!
Please Log in or Register to access more feature in this site.
Start Learning!

† Copyright ©️ 2011 - EliteCoders.forums.ag †
Elite Coders Society
Hello Guest!
Join us here in this forum!
Please Log in or Register to access more feature in this site.
Start Learning!

† Copyright ©️ 2011 - EliteCoders.forums.ag †


Start sharing and learning new skills about programming and design by building connections with other professional and students.
 
HomeForumData Sorting: BubbleSort Java 2a512xyPortalLatest imagesGalleryData Sorting: BubbleSort Java Dw6hztSearchData Sorting: BubbleSort Java 2ns506pData Sorting: BubbleSort Java 2dt2b75RegisterLog in
Elite Coders Partner Links

EliteCoders™️ News!
Hello Guest!, Welcome in our forum. Be active!

Share | 
 

 Data Sorting: BubbleSort Java

View previous topic View next topic Go down 
AuthorMessage
Admin[dElmARk]
Admin[dElmARk]
Forum Owner
Forum Owner

Posts : 78
EC-Points : 6304
Thanked : 21
Join date : 15/10/2011
Age : 28
Location : Philippines

Hacker's Info
Hacking Exp:
Data Sorting: BubbleSort Java Left_bar_bleue0/0Data Sorting: BubbleSort Java Empty_bar_bleue  (0/0)
Hacker Type: White Hat
Hacking Title:

Data Sorting: BubbleSort Java Empty
PostSubject: Data Sorting: BubbleSort Java   Data Sorting: BubbleSort Java EmptyTue Nov 29, 2011 9:20 am

BubbleSort Java

Code:

public class BubbleSort{
 public static void main(String[] args){
  int intArray[]=new int[]{5,90,35,45,150,3};
  System.out.println("Array Before Bubble Sort");
  for(int i=0; i< intArray.length; i  )
  {
  System.out.print(intArray[i]  " ");
  }
  //sort an array using bubble sort algorithm
  bubbleSort(intArray);
  System.out.print("");
  //print array after sorting using sort algorithm
  System.out.println("Array After Bubble Sort");
  for(int i=0; i< intArray.length; i  )
  {
  System.out.print(intArray[i]  " ");
  }
 }
 private static void bubbleSort(int[]intArray)
 {
  int n = intArray.length;
  int temp = 0;
  for(int i = 0; i< n; i  )
  {
  for(int j=1; j<(n-i); j  )
  {
    if(intArray[j-1] > intArray[j])
    {
      temp=intArray[j-1];
      intArray[j-1]=intArray[j];
      intArray[j]=temp;
      }
    }
  }
  }
 }

Activity:
Create a program that will interact with the user.

The program must do the following:
1. Ask the user "How many numbers will be sorted? "
2. Display the unsorted numbers.
3. Display the sorted numbers in ascending order.
4. Display the sorted numbers in descending order.
Back to top Go down
 

Data Sorting: BubbleSort Java

View previous topic View next topic Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Elite Coders Society :: Software Development :: Java Programming :: Java Programming-

Protected by Copyscape Duplicate Content Finder
Powered By EliteCoders™

Elite Coders Partner Links
GreyPhantomYour Link HereYour Link HereYour Link Here
Yahoo!GoogleFacebookForumotion