Responsive Ads Here

Wednesday, April 27, 2016

Write a program for Bubble Sort in java



1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class BubbleSort {

 public static void main(String[] args) {
  float a[] = new float[5];
  Scanner scanner = new Scanner(System.in);
  System.out.println("please Enter Number : ");
  float temp;
 // input
  for (int i = 0; i < a.length; i++) {
   a[i] = scanner.nextFloat();
  }
 // sorting Bubble
  for (int i = 0; i < a.length - 1; i++) {
   for (int j = 0; j < a.length - 1 - i; j++) {
    if (a[j] > a[j + 1]) {
     temp = a[j + 1];
     a[j + 1] = a[j];
     a[j] = temp;
    }
   }
  }
 // output
  System.out.println("OutPUT of this program : ");
  for (int i = 0; i < a.length; i++) {
   System.out.println(a[i]);
  }
 }

}




No comments:

Post a Comment

php4

<?php    // Start the session  session_start();  ?>  <!DOCTYPE html>  <html>  <head>       <link rel=&q...