Created
April 3, 2013 03:44
-
-
Save zhuhai/5298291 to your computer and use it in GitHub Desktop.
冒泡排序法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class L5{ | |
public static void main(String[] args){ | |
int[] nums=new int[5]; | |
for(int a=0;a<nums.length;a++){ | |
System.out.println("请输入"+(a+1)+"个整数的值:"); | |
nums[a]=input.nextInt(); | |
} | |
System.out.println("你输入的数为:"); | |
for(int a=0;a<nums.length;a++){ | |
System.out.print(nums[a]+" "); | |
} | |
for(int i=0;i<nums.length-1;i++){ | |
for(int j=0;j<nums.length-i-1;j++){ | |
if(nums[j]>nums[j+1]){ | |
int temp=nums[j]; | |
nums[j]=nums[j+1]; | |
nums[j+1]=temp; | |
} | |
} | |
} | |
System.out.println("\n按从小到大排序,结果为:"); | |
for(int n:nums){ | |
System.out.print(n+" "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment