Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BubbleSort {
- public static void main(String[] args){
- Scanner scan = new Scanner(System.in);
- int[] myArray = new int[10];
- System.out.println("Enter 10 numbers");
- for(int i=0;i<10;i++){
- myArray[i]=scan.nextInt();
- }
- System.out.println();
- bubbleSort(myArray);
- }
- public static void bubbleSort(int[] array){
- for(int i = 0; i < array.length - 1; i++){
- for(int j = 0; j < array.length -1 - i; j++){
- if(array[j] > array[j+1]){
- int temp = array[j+1];
- array[j+1] = array[j];
- array[j] = temp;
- }
- }
- }
- for(int i = 0; i < array.length; i++){
- System.out.print(array[i] + ",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement