日期:2014-05-17 浏览次数:20719 次
import java.util.Scanner; public class Foree { public static void rangeAry(int[] ary){ for(int i=0;i<ary.length;i++){ for(int j=0;j<ary.length-1;j++){ if(ary[j]>ary[j+1]){ int temp=ary[j]; ary[j]=ary[j+1]; ary[j+1]=temp; } } } } public static void main (String[] args){ int[] ary=new int[3]; Scanner input = new Scanner(System.in); System.out.print("请输入第一个整数"); ary[0] = input.nextInt(); System.out.print("请输入第二个整数"); ary[1] = input.nextInt(); System.out.print("请输入第三个整数"); ary[2] = input.nextInt(); rangeAry(ary); for(int i:ary){ System.out.print(i+","); } } }
------解决方案--------------------
给你个思路吧
排序法
int[] m = {2,10,4,7,5,8,6,9,1,3};
for(int i = 0;i < m.length - 1;i++) //排序次数
{
//两两比较,实现排序
for(int j = 0;j < m.length - 1 - i;j++)
{
if(m[j] < m[j + 1])
{
//交换
int temp = m[j];
m[j] = m[j + 1];
m[j + 1] = temp;
}
}
}
------解决方案--------------------
import java.util.*; class foree { public static void main (String[] args) { Scanner input =new Scanner(System.in); System.out.print("请输入第一个整数"); int a = input.nextInt(); System.out.print("请输入第二个整数"); int b = input.nextInt(); System.out.print("请输入第三个整数"); int c = input.nextInt(); int temp; if(a>b) { temp=a; a=b; b=temp; } if(a>c) { temp=a; a=c; c=temp; } if(b>c) { temp=b; b=c; c=temp; } System.out.println(a+","+b+","+c); } }