Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class BubbleSort {
  3. public static void main(String[] args){
  4. Scanner scan = new Scanner(System.in);
  5. int[] myArray = new int[10];
  6. System.out.println("Enter 10 numbers");
  7. for(int i=0;i<10;i++){
  8. myArray[i]=scan.nextInt();
  9. }
  10. System.out.println();
  11. bubbleSort(myArray);
  12. }
  13. public static void bubbleSort(int[] array){
  14. for(int i = 0; i < array.length - 1; i++){
  15. for(int j = 0; j < array.length -1 - i; j++){
  16. if(array[j] > array[j+1]){
  17. int temp = array[j+1];
  18. array[j+1] = array[j];
  19. array[j] = temp;
  20. }
  21. }
  22. }
  23. for(int i = 0; i < array.length; i++){
  24. System.out.print(array[i] + ",");
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement