VB icon

Bubble Sort Program

Email
Submitted on: 8/5/2015 1:19:17 PM
By: Jake R. Pomperada  
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.1), Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 299
author picture
 
     In this article I would like to share with you one of the most common sorting algorithm used in computer science it is called bubble sort. Basically we use sorting to arrange the values in ascending or descending order. What our program does is to ask the user how many items to be sorted and then our program will ask the user to enter a series of values. After which our program will display the original values and it will display the ascending and descending order of values after it is processed by our program using bubble sort algorithm. If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360. Thank you very much and Happy Programming.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Bubble Sort Program
// Description:In this article I would like to share with you one of the most common sorting algorithm used in computer science it is called bubble sort. Basically we use sorting to arrange the values in ascending or descending order. What our program does is to ask the user how many items to be sorted and then our program will ask the user to enter a series of values. After which our program will display the original values and it will display the ascending and descending order of values after it is processed by our program using bubble sort algorithm.
If you have some questions about programming, about my work please send mu an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360.
Thank you very much and Happy Programming.
// By: Jake R. Pomperada
//**************************************

// bubble_sort.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// August 5, 2015Wednesday
// Create a program that uses bubble sort algorithm with the following results.
//BUBBLE SORT PROGRAM
//How many values :6
//Enter value in item no.1: 540
//Enter value in item no.2: 313
//Enter value in item no.3: 741
//Enter value in item no.4: -456
//Enter value in item no.5: 600
//Enter value in item no.6: 341
//
//BEFORE SORTING
//540 313 741 -456 600 341 
//AFTER SORTING
//
//ASCENDING ORDER
//
 // -456 313 341 540 600 741
//DESCENDING ORDER
//741 600 540 341 313 -456
//	 THANK YOU FOR USING THIS PROGRAM
import java.util.Scanner;
 
class bubble_sort {
	
	public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
	
int items[] = null;
	int values = 0;
System.out.print("BUBBLE SORT PROGRAM");
System.out.println();
	System.out.print("How many values :");
	values = scan.nextInt();
items = new int[values];
for(int i=0; i<values; i++)
 {
System.out.print("Enter value in item no." + (i+1) + ": "); 
items[i] = scan.nextInt();
}
System.out.println();
	System.out.print("BEFORE SORTING");
	System.out.println();	
	for(int i=0; i<values; i++) 
 {
		System.out.print(items[i] + " ");
	 }
	for(int i = 0; i < values; i++) {
	 for(int j = 1; j < (values-i); j++) {
	if(items[j-1] > items[j]) {
	 int temp = items[j-1];
 items[j-1] = items[j];
		 items[j] = temp;
		}
	}
	}
System.out.println();
	System.out.println("AFTER SORTING");
System.out.println();
	System.out.println("ASCENDING ORDER");
System.out.println();
 
	for(int i=0; i<values; i++) 
 {
	 System.out.print(" " + items[i]);
	 }
System.out.println();	
	System.out.print("DESCENDING ORDER");
 System.out.println();
	for(int i=values-1; i>=0; i--)
{
	System.out.print(" " + items[i]);
	}
System.out.println("\n\n");
System.out.print("\t THANK YOU FOR USING THIS PROGRAM"); 
System.out.println();	
}
}


Other 9 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.