Thursday 14 January 2016

Java program for bubble sort


import java.util.Scanner;
class Main{
public static void main(String args[])
{
int i,d,temp;
int number=8;
int list[]=new int[number];
Scanner input=new Scanner(System.in);
for(i=0;i<number;i++)
{
System.out.println("Enter the numbers");
list[i]=input.nextInt();
}
for(i=0;i<number;i++){
for(d=0;d<number-i-1;d++){
if(list[d]>list[d+1]){
temp=list[d];
list[d]=list[d+1];
list[d+1]=temp;
}
}
}
for(i=0;i<number;i++){
System.out.println("Bubble sorted list are "+list[i]);
}
}
}


OUTPUT:-
C:\Users\saty\Desktop>javac 1.java
C:\Users\saty\Desktop>java Main
Enter the numbers
24
Enter the numbers
5
Enter the numbers
86
Enter the numbers
12
Enter the numbers
34
Enter the numbers
56
Enter the numbers
4
Enter the numbers
28
Bubble sorted list are 4
Bubble sorted list are 5
Bubble sorted list are 12
Bubble sorted list are 24
Bubble sorted list are 28
Bubble sorted list are 34
Bubble sorted list are 56
Bubble sorted list are 86

12 comments:

  1. It's awesome
    helpful for my coding

    ReplyDelete
  2. All I can say about this tutorial is "Woooow"

    ReplyDelete
  3. I guess you're a great teacher by birth! Excellent tutorial

    ReplyDelete
  4. Very Useful, Simple and clear..Thanks !!!!

    ReplyDelete
  5. Really helpful and simple ...

    ReplyDelete
  6. I guess you're a great teacher by birth

    ReplyDelete
  7. Your a good teacher. it's nice way to teach the lessons for all

    ReplyDelete
  8. wow this is complete and compact, thank you sir

    ReplyDelete