Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class BubbleSort {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- boolean swap = false;
- int buffer = 1;
- int[] nums = new int[5];
- for ( int i=0; i<5; i++) {
- nums[i]=scanner.nextInt();
- }
- do {
- swap = false;
- for(int i=1; i<5; i++) {
- if(nums[i]<nums[i-1]) {
- buffer = nums[i];
- nums[i]=nums[i-1];
- nums[i-1]=buffer;
- swap=true;
- }
- }
- }while(swap);
- for(int i=0;i<5;i++) {
- System.out.println(nums[i]);
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement